小编Ele*_*ate的帖子

我的if语句在我的while循环中的每个if语句上打印,无论它是否为false

所以我正在做一个文字冒险游戏,我只是编程指导。我有一个带有南北等的脚本,然后是一条if语句,该语句表明如果用户输入的不是方向,它会说这不是方向,并循环到顶部,但不起作用。即使我输入正确的输入,也将始终打印那不是方向。有人可以帮忙吗?

#include <iomanip>
#include <string>
#include <iostream>
using namespace std;



int main()
{
    string input;
    while (input != "north", "n", "south", "s", "east", "e") {
        cout << "Enter a direction" << endl;
        getline(cin, input);
        if (input == "north" || input == "n") {
            cout << "north" << endl;
        }
        if (input == "west" || input == "w") {
            cout << "west" << endl;
        }
        if (input == "east" || input == "e") {
            cout << "east" << endl;
        }
        if …
Run Code Online (Sandbox Code Playgroud)

c++ if-statement

2
推荐指数
1
解决办法
90
查看次数

标签 统计

c++ ×1

if-statement ×1