【发布时间】:2016-12-05 06:01:39
【问题描述】:
int OnLoad() {
cout << "Hi whats your name? ";
cin >> name;
system("cls");
cout << "Hi " << name << "." << " Are you here to Take Over the city from zombies?"<< endl;
cin >> userInput;
if (userInput == "yes" || "Yes") {
cout << "Yes" << endl;
}
else if (userInput == "no" || "No") {
cout << "No" << endl;
}
else {
cout << "I don't understand." << endl;
}
return 0;
}
int main() {
OnLoad();
system("pause");
return 0;
}
此代码仅返回是,在控制台窗口弹出并询问你是否在这里从僵尸手中接管城市后,即使我输入否它返回是!
【问题讨论】:
-
|| "Yes"不会按照你的想法去做。它实际上总是评估为真!你想要if ( (userInput == "yes") || (userInput == "Yes")) -
我确信这个问题有数百个(如果不是数千个)重复,所以我不会发布正式答案。
-
谢谢,其实我已经开始尝试这个了,但我认为这是错误的。大声笑。