c ++ if else 语句不会进入文本冒险游戏的正确路径,总是进入相同的 Void 函数

c++ if else statement won't go right pathway for text adventure game, always goes to the same Void Function

我有 C++ 问题。 在我正在制作的文字冒险游戏中,在我可以选择在房子里做什么的不同选项的部分,我所做的每一个选择总是进入 void Sleep() 函数:

void Home()
{
    cout << "\nYou are in the living room of your rented home. Everything looks nice and tidy." << endl;
    cout << "Choices:" << endl;
    cout << "Sleep" << endl;
    cout << "Leave" << endl;
    cout << "Stats" << endl;
    cin >> choice;

    if (choice == "Sleep" || "sleep")
    {
        Sleep(); // No matter what choice I make, it always
        //goes to the Sleep(); void.
    }
    if (choice == "Leave" || choice == "leave"){
        TownSquare();
    } if (choice == "Stats" || choice == "stats") {
        StatsH();
    }
    else {
        cout << "Please choose correctly!" << endl;
        Home();
    }
}

我们将不胜感激。谢谢!

您的线路:

if (choice == "Sleep" || "sleep")

评估为:

if ((choice == "Sleep") || "sleep")

这总是正确的,因为 "sleep" 总是会触发。您可能需要在此处进行适当的查找 table,如果担心的话,将输入强制设为小写。