执行下面这条语句,根本不给输入的机会!咋办
printf(“你是否要继续玩?N/Y\n”);/当3次机会用完但没有答对的时候,提示要不要继续玩/
fflush(stdin);
scanf("%c", &answer);
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<stdbool.h>
#include<ctype.h>
int main()
{
printf(“这是一个西蒙游戏!\n”);
//定义各种变量
bool correct = 1;
char answer = ‘y’;
unsigned int digits = 2;
unsigned int tries = 0;
unsigned int DELEY = 2;
unsigned int start_time = 0;
time_t seed=0;
unsigned int cai = 0;
//游戏介绍
//游戏开始的循环
do {
//玩家开始时初始化相关游戏数据
digits = 2;
tries = 0;
correct = 1;
while (correct)
{
start_time=clock();
++tries;/记录游戏次数/
//生成随机数字
srand(time(&seed));/种下随机种子,且将种下种子的时间存储到seed地址/
for (unsigned int i = 1; i <= digits; ++i)
printf("%d “, rand() % 10);/根据不同种子,生成不同数据,且随机数在0-9之间/
//控制数字串存在的时间
for (; clock() - start_time < DELEY*CLOCKS_PER_SEC;)
printf(”\r");//回到最初位置
for (unsigned int i = 1; i <= digits; ++i)
printf(" ");//消除之间的随机数字
//接下来需要输入数据,看之前的随机数是否相同
srand(seed);/*引用之前的种子值*/
printf("\r");//回到最初位置
if (tries == 1)
printf("请输入你看到的数字:\n");
for (unsigned int i = 1; i <= digits; ++i)
{
scanf("%u", &cai);
if (cai != rand() % 10)
{
correct = 0; break;
}
}
//游戏玩3次,
if (correct&& tries % 3 == 0)//如果玩够三次且正确,那么加数字串个数
++digits;
printf("%s!\n", correct ? "correct" : "wrong");//回复正确
}
//计分系统
printf("你是否要继续玩?N/Y\n");/*当3次机会用完但没有答对的时候,提示要不要继续玩*/
fflush(stdin);
scanf("%c", &answer);
} while (tolower(answer)=='y');
system("pause");
return 0;
}