首先会弹出菜单,其中显示了用户可以购买的商品列表。然后询问用户是否要结账或继续购物。当用户在提示后键入“no”而不是menu();被召唤将他们带回菜单。什么都没发生。我可以输入控制台,但没有其他任何显示。
以下是问题的代码,它的功能不同:
cout << "Would you like to checkout?" << endl;
cout << "Type 'yes' to continue or 'no' to keep shopping." << endl;
cin >> answer;
if (answer == "yes") {
checkout(mpadNum, mouseNum, hsetNum, keyboardNum, laptopNum, pcNum);
}
else if (answer == "no") {
menu(mpadNum, mouseNum, hsetNum, keyboardNum, laptopNum, pcNum);
}
如果需要,以下是部分菜单功能的代码:
void menu(int mpadNum, int mouseNum, int hsetNum, int keyboardNum, int laptopNum, int pcNum) {
int *mpadQty;
string answer;
string option;
if (file.is_open()) {
cout << file.rdbuf();
}
cout << " " << endl;
cout << "What would you like to purchase?" << endl;
cout << "Please type your selection." << endl;
cin >> option;
if (option == "mousepad") {
cout << "How many mousepads would you like?" << endl;
cin >> mpadNum;
}
mpadQty = new int(mpadNum);
mpadAmnt += *mpadQty;
cout << "Your selection has been added to the cart" << endl;
cout << "Type anything to continue." << endl;
cin >> answer;
cart(mpadNum, mouseNum, hsetNum, keyboardNum, laptopNum, pcNum);
}
答案 0 :(得分:0)
这是一个调试提示。尝试在行answer
之后打印cin >> answer
。
cout << "answer->" << answer << "<-" << endl;