#include
#include
#include
int main(void)
{
srand((unsigned int)time(NULL)*10);
int num1 = rand() %32 + 1;
int num2;
int cs = 0;
int game = 0;
int best;
int last;
if (game < 4)
{printf("Please enter a number in 1-32, which you think is the same with computer:\n");
scanf("%d",&num2);
if (num1 == num2)
{
cs++;
printf("You are correct!\n");
}
else
{
cs++;
printf("You are wrong!Try again.\n");
do{
printf("Please enter a number, which you think is the same with computer:\n");
scanf("%d",&num2);
printf("You are wrong again!");
cs++;
} while(num1 == num2);
}
printf("Your grades is %d.\n",cs);
printf("Write down your last time best grade :");
scanf("%d",&last);
if (cs < last)
{
best = cs;
printf("Your best score now is %d.",best);
}
else
{
best = last;
printf("Your best score now is %d.",best);
}
}
else
{
printf("You have finished this game now!\n Here is your best grade:%d.\n",best);
}
return 0;
}
31行,num1 != num2
不等于就继续循环,等于就退出
你写的代码应该有死循环了do while那里猜中了还是在循环,应该num1!=num2 可以看一下这篇猜数字游戏,文章最后有源码 http://t.csdn.cn/linfx