我没有任何代码,但假设用户应该在 2 分钟内回答数学问题并生成它的分数:
样本输出1:
1+2 = *user's answer*
1+5 = *user's answer*
5+6 = *user's answer*
9+0 = *user's answer*
5+8 = *user's answer*
2+9 = *user's answer*
Time: 0:2:0:0
Time's up!
Your score: 6
样本输出2:
1+2 = *user's answer*
1+5 = *user's answer*
5+6 = *user's answer*
9+0 = *user's answer*
Time: 0:2:0:0
Time's up!
Your score: 4
代码:
void add() //Addition
{
int x,num,num2,ans,sum,score=0;
time_t t;
clrscr();
for(x=0;x<5;x++) // I tried for(x=0;x<=time();x++) but compiled error
{
srand((unsigned) time(&t));
num=rand()%9;
num2=rand()%9;
sum=num+num2;
gotoxy(30,14);
clrscr();
printf("\n%d + %d = ",num,num2);
printf("\nAns: ");
scanf("%d",&ans);
if(ans==sum)
{
score++;
}
else
{
printf("\nengggk!!!\n");
}
}
printf("\n\t\t\t ....Your score: %d",score);
pass(score);
}
void time()
{
int h,m,s;
clrscr();
for(h=0;h<12;h++)
{
for(m=0;m<60;m++)
{
for(s=0;s<60;s++)
{
printf("TIMER::\n%d:%d:%d",h,m,s);
if(m==2)
{
printf("Time's up!");
pass();
return m;
}
}
}
}
我真的不知道该怎么做,请帮助我。
谢谢你。