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;
}
此代码只返回是回来后,控制台窗口弹出并要求你在这里从僵尸接管城市,即使我输入否,它返回是!为什么这只返回“是”
'|| “是”不符合你的想法。它总是评估为真!你想'if((userInput ==“yes”)||(userInput ==“Yes”))' – drescherjm
我确信有这个问题的数百(如果不是数千)重复,所以我不会发表正式答案。 – drescherjm
谢谢,我其实开始尝试这个,但我认为这是错误的。大声笑。 – Remi