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