gpt4 book ai didi

C++ if/else if 语句不能正常工作

转载 作者:搜寻专家 更新时间:2023-10-31 00:31:13 24 4
gpt4 key购买 nike

<分区>

我正在尝试编写一个类似游戏的小冒险程序,我需要其中的 if else 语句才能正常工作。但是,每当我运行此 if else 语句时,它都不会输出我想要的内容。

#include <iostream>

using namespace std;

int main()
{
while(true)
{
cout << endl << "What will you do?: ";
string input;
cin >> input;
if (input == "Nothing" || input == "nothing")
{
cout << "Why would you do nothing?" << endl;
}
else if (input == "Look North" || input == "Look north" || input == "look North" || input == "look north")
{
cout << "You look north. There is nothing north." << endl;
}
}
}

我希望它输出的是这样的:

What will you do?: nothing
Why would you do nothing?

What will you do?: look north
You look north. There is nothing north.

What will you do?:

但是,当我将它们作为输入时,我没有得到它,而是得到了这个:

What will you do?: nothing
Why would you do nothing?

What will you do?: look north

What will you do?:
What will you do?:

我需要一些帮助来解决这个问题,因为我找不到为什么会发生这种情况的答案。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com