[英]Why do i keep getting a weird output in 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;
}
for example I will type in "a" as my character and the output will be -85993640 I originally had char1 instead of a, I also tried putting "char" next to "a" and char1 例如,我将输入“ a”作为我的字符,输出将是-85993640,我原来是char1而不是a,我也尝试将“ char”放在“ a”和char1旁边
Store the value that you need into a char variable instead of an Integer variable, as you are asking for character input 要求输入字符时,将所需的值存储在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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.