#include
#include
#include
#include
#include
int main (void)
{
srand(time(NULL));
int r,num=0;
r=rand()%100+1;
do
{
system("cls");
printf ("Please try to guess this number\n");
printf ("If you want to exit this program please press any key button between 'a' to 'z' or press 'ESC'\n");
printf ("Please enter a whole number between 1 to 100: ");
scanf("%d",&num);
if ((num < r)&&(num>0))
{
printf("Your guessed too low");
}
else if ((num >r)&&(num<100))
{
printf("Your guessed too high");
}
else if (num ==r )
{
printf ("Your guessed correctly\n");
printf ("The correct answer is %d",r);
Sleep(2000);
exit (0);
}
else if ((getch()>='a')&&(getch()<='z'))//第二次你读的字符被这里吃了
{
printf("\nThank you for using our program!");
Sleep(2000);
exit (0);
}
else
{
printf("\nOut of range");
Sleep(2000);
exit (0);
}
}while (getch()!= 27);//这里又让输入了,不是循环卡住了,而是要多输,你把程序改改吧
return 0;
}