if (!(cin.good())) cout << "No letters" << endl; 如果我输入字母,我会不停地重复,但其他字母工作得很好。说不出为什么。
#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;
}