有人可以帮我弄清楚为什么它不起作用吗?

时间:2021-05-30 13:16:53

标签: c++

#include <iostream>
using namespace std;

int main()
{

    char name;
    int Number;

    cout << "What is your name " << endl;
    cin >> name;
    cout << "Enter a number between 1 and 5 " << endl;
    ;
    cin >> Number;

    if (Number == 1) {
        cout << "Hello " << name << endl;
    }
    else if (Number == 2) {
        cout << "Greetings " << name << endl;
    }
    else if (Number == 3) {
        cout << "Hiya, how are you " << name << endl;
    }
    else if (Number == 4) {
        cout << "Howdy! " << name << endl;
    }
    else if (Number == 5) {
        cout << "What's up " << name << endl;
    }
    return 0;
}

"编写一个程序:

询问用户名。 要求用户输入 1 到 5 之间的数字。 根据他们选择的号码输出个性化的问候语(包括用户的姓名)(每个号码应该有一个唯一的问候语)。”

我似乎无法理解如何让它工作,每当我输入一个数字时,它都会给我错误,“bash: 1: command not found”

1 个答案:

答案 0 :(得分:0)

char 类型仅存储 1 个字符。如果要存储多个字符,请使用 char[]std::string

char name[100];
std::string name;