该行if(!(cin.good()))cout < <“无字母”< < endl;如果我输入字母不断重复不停,但其他工作正常。无法说明原因。C++ cout不断重复
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <cstdio>
using namespace std;
int main()
{
int x;
cout << "Please enter a number\n";
srand(time(0));
int y = rand();
while (x != y)
{
cin >> x;
if (!(cin.good()))
cout << "No letters" << endl;
else if (x < y)
cout << "Go higher" << endl;
else if (x > y)
cout << "Go lower" << endl;
else
cout << "You win!!" << endl;
}
cin.get();
getchar();
return 0;
}
现在它说错误:'else'没有以前的'if' – Foxic 2012-04-19 00:03:51
@ 30trix那么你还有其他类型的错字。可能忘记了最后的大括号?或者完全省略括号? – 2012-04-19 00:05:07