冰淇淋问题 [英] Ice Cream Problem

查看:103
本文介绍了冰淇淋问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家好,好吧,这个问题给我带来了一些麻烦。我让它迭代但我希望它在用户键入错误选择时生成错误消息。我收到了错误消息但是我觉得我的do-while循环可能有问题。它不会正常执行。每当我想执行另一个事务时,我的错误消息就会弹出。任何帮助将不胜感激。




< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

解决方案


大家好,好的,这个问题给了我一些麻烦。我让它迭代但我希望它在用户键入错误选择时生成错误消息。我收到了错误消息但是我觉得我的do-while循环可能有问题。它不会正常执行。每当我想执行另一个事务时,我的错误消息就会弹出。任何帮助将不胜感激。





#include< iostream>

#include< iomanip>

using namespace std;


int main()

{


cout<< setprecision(2)

<< setiosflags(ios :: fixed)

<< setiosflags(ios :: showpoint);


char选择,

停止;


double choco_D = 0.50,

van_S = 0.50,
straw_B = 0.65;


double num_needed = 0;


do

{

cout<< " \t ********************************************* ** ********* \ n" ;;

cout<< "欢迎来到Rainbow Ice Cream \ n";

cout<< " \t ============================================= == ========= \ n" ;;

cout<< " \t C - Chocolate Deluxe ** \ n";

cout<< " \t V - Vanilla Special ** \ n";

cout<< \t S - Strawberry Burst ** \ n;

cout<< endl;

cout<< \t请选择你的冰淇淋口味:" ;;

choice = cin.get();

cout<< \ n \ nn;


开关(选择)

{

case''C'':

cout<< \t你选择了Chocolate Deluxe \ n \ nn ;;

cout<< \t请输入所需的冰淇淋数量:;

cin>> num_needed;

cout<< " \t" << num_needed<< " Chocolate Deluxe,


" << (num_needed * choco_D)<< \ n \ nn;

休息;

案例''V'':

cout<< \t你选择了Vanilla Specialt \ nn \ nn ;;

cout<< \t请输入所需的冰淇淋数量:;

cin>> num_needed;

cout<< " \t" << num_needed<< " Vanilla Special,


" << (num_needed * van_S)<< \ n \ nn;

休息;

案例''S'':

cout<< \t你选择了Strawberry Burst \ n \\ nn ;

cout<< \t请输入所需的冰淇淋数量:;

cin>> num_needed;

cout<< " \t" << num_needed<< " Strawberry Burst,


Hey everyone, Ok, this problem is giving me some trouble. I got it to iterate but I want it to generate an error message if a user types in an incorrect choice. I got the error message down however I think something may wrong with my do-while loop. It wont execute properly. Whenever I want to perform another transaction, my error message pops up. Any help will be appreciated.






Expand|Select|Wrap|Line Numbers

解决方案

Hey everyone, Ok, this problem is giving me some trouble. I got it to iterate but I want it to generate an error message if a user types in an incorrect choice. I got the error message down however I think something may wrong with my do-while loop. It wont execute properly. Whenever I want to perform another transaction, my error message pops up. Any help will be appreciated.






#include <iostream>
#include <iomanip>
using namespace std;


int main()
{

cout <<setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);


char choice,
stop;

double choco_D = 0.50,
van_S = 0.50,
straw_B = 0.65;

double num_needed = 0;


do
{
cout << "\t*********************************************** *********\n";
cout << " Welcome to Rainbow Ice Cream \n";
cout << "\t=============================================== =========\n";
cout << "\t C - Chocolate Deluxe **\n";
cout << "\t V - Vanilla Special **\n";
cout << "\t S - Strawberry Burst **\n";
cout << endl;
cout << "\t Please select your flavor of Ice Cream: ";
choice = cin.get();
cout << "\n\n";

switch (choice)
{
case ''C'':
cout << "\t You have chosen Chocolate Deluxe\n\n";
cout << "\t Please enter the number of Ice creams needed: ";
cin >> num_needed;
cout << "\t" << num_needed << " Chocolate Deluxe,


" << (num_needed * choco_D)<< "\n\n";
break;
case ''V'':
cout << "\t You have chosen Vanilla Special\n\n";
cout << "\t Please enter the number of Ice creams needed: ";
cin >> num_needed;
cout << "\t" << num_needed << " Vanilla Special,


" << (num_needed * van_S) << "\n\n";
break;
case ''S'':
cout << "\t You have chosen Strawberry Burst\n\n" ;
cout << "\t Please enter the number of Ice creams needed: ";
cin >> num_needed;
cout << "\t" << num_needed << " Strawberry Burst,


这篇关于冰淇淋问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆