我正在制作一台没有面向对象的基本自动售货机,并且由于某种原因需要一个菜单系统,即使我在菜单中输入2,如果满足条件则选择第一个并且打印出2个你的巧克力棒先生"当我想要一个Museli酒吧!
#include <iostream>
#include <string>
using namespace std;
int main()
{
int Choclate=0;
int Museli=0;
int CheesePuffs;
int Apple;
int Popcorn;
int menuChoice = 0;
while (menuChoice != -1)
{
cout << "-ENTER CORRESPONDING NUMBER-" << endl;
cout << "1. Milk Choclate Bar" << endl;
cout << "2. Museli Bar" << endl;
cout << "3. Cheese Puffs" << endl;
cout << "4. Apple" << endl;
cout << "5. Popcorn" << endl;
cout << "Enter Choice: ";
cin >> menuChoice;
if (menuChoice = 1)
{
Choclate = Choclate + 1;
cout << "Here's your choco bar sir." << endl;
}
else if (menuChoice = 2)
{
Museli = Museli + 1;
cout << "Here's your museli bar sir." << endl;
}
}
}
答案 0 :(得分:4)
您需要使用==
即
if (menuChoice == 1)
最好还是查看switch