问题遇到的现象和发生背景 游戏目的是:电脑随机生成一个数,然后玩家输入一个数,看几次可以相同。我想要做到一个人重复四次游戏,且一次游戏里一直猜测直到相同。
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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;
}
运行结果及报错内容 玩家输入两次后就结束了,没有一直在循环里,不知道为什么
我的解答思路和尝试过的方法
我想要达到的结果 玩家一直循环,直到猜中当局随机数