模拟一个点菜界面

突发奇想,写了一个小代码,模拟餐馆点菜的形式。首先,假设只有三种菜品:番茄炒蛋,蒜泥生菜,椒盐明虾,点菜时按字母 'a'、'b'、'c' 代表每种菜品,按下字母 'P' 表示停止点菜,最后显示出订单信息,并计算金额。

#include
using namespace std;
int main(){
char dish;
int amount[3];
int sum = 0;
bool operat = true;
cout << "菜单价目如下:" << endl;
cout << "番茄炒蛋   3 元" << endl;
cout << "蒜泥生菜   5元" << endl;
cout << "椒盐明虾   7元" << endl;
cout <while (operat){
cout << "输入菜名:"; cin >> dish;
operat = dish == 'P' ? false : true;
switch (dish){
case('a') :
cout << "番茄炒鸡蛋,份数:";
cin >> amount[0];
sum = sum + 3 * amount[0];
break;
case('b') :
cout << "蒜泥生菜,份数:";
cin >> amount[1];
sum = sum + 5 * amount[1];
break;
case('c') :
cout << "椒盐明虾,份数:";
cin >> amount[2];
sum = sum + 7 * amount[2];
break;
}
}
cout << endl<<"菜单明细:" << endl;
if (amount[0]>0)
cout << "番茄炒蛋 " << amount[0] << "份,$" << 3 * amount[0] << endl;
if (amount[1]>0)
cout << "蒜泥生菜 " << amount[1] << "份,$" << 5 * amount[1] << endl;
if (amount[2]>0)
cout << "椒盐明虾 " << amount[2] << "份,$" << 7 * amount[2] << endl;
cout << "消费总额:" <return 0;
}

你可能感兴趣的:(C++学习)