小编Ste*_*yes的帖子

如何在else-if语句中正确使用or语句(||)

考虑以下代码:

string GameExit;
bool GameChoiceGo = true;

while (GameChoiceGo == true)
{
    system("cls"); 
    cout << "\n  Are you sure you want to exit? (Yes or No)     ";
    cin >>  GameExit;
    if (GameExit == "y" || "Y" || "yes" || "Yes" || "YES")
    {
        cout << "User typed Yes";
        Sleep(3000);
        system("cls");
        break;
    }
    if (GameExit == "n" || "N" || "no" || "No" || "NO")
    {
        cout << "User typed No";
        Sleep(3000);
        system("cls");
        GameChoiceGo = false;
    }
    else
    {
        cout << …
Run Code Online (Sandbox Code Playgroud)

c++ if-statement logical-operators

0
推荐指数
1
解决办法
129
查看次数

标签 统计

c++ ×1

if-statement ×1

logical-operators ×1