为什么我一直在用c ++获得一个奇怪的输出

时间:2015-03-21 14:50:10

标签: c++

{
int x, a;
cout << "Please enter the amount of squares" << endl;
cout << "Pick a number between 1 and 10" << endl;
cin >> x;
cout << "Now enter a character" << endl;
cin >> a;
if (x == 1)
    cout <<"\t"<< a << endl;

return 0;
}
例如,我将输入“a”作为我的角色,输出将为-85993640 我最初使用char1而不是a,我也尝试将“char”放在“a”和char1

旁边

1 个答案:

答案 0 :(得分:0)

将所需的值存储到char变量而不是Integer变量中,因为您要求输入字符

 {
    char a;
    int x;
    cout << "Please enter the amount of squares" << endl;
    cout << "Pick a number between 1 and 10" << endl;
    cin >> x;
    cout << "Now enter a character" << endl;
    cin >> a;
    if (x == 1)
        cout <<"\t"<< a << endl;

    return 0;
    }