Why is this only returning “yes”

前端 未结 2 1540
既然无缘
既然无缘 2021-01-28 20:05
int OnLoad() {
cout << \"Hi whats your name? \";
cin >> name;
system(\"cls\");
cout << \"Hi \" << name << \".\" << \" Are you here to         


        
2条回答
  •  粉色の甜心
    2021-01-28 20:20

    that's not how the || operator works, if you just put "Yes" as a condition it will always evaluate to true

    if (userInput == "yes" || userInput == "Yes") {
        cout << "Yes" << endl;
    }
    

    the reason why is because of precedence

    userInput == "yes"
    

    and

    userInput == "Yes"
    

    get evaluated before || ( logical OR)

提交回复
热议问题