函数调用不起作用,但控制台仍然允许输入。

时间:2017-12-11 22:12:00

标签: c++

首先会弹出菜单,其中显示了用户可以购买的商品列表。然后询问用户是否要结账或继续购物。当用户在提示后键入“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);

}

1 个答案:

答案 0 :(得分:0)

这是一个调试提示。尝试在行answer之后打印cin >> answer

cout << "answer->" << answer << "<-" << endl;