满意答案
uisb80124
2013.05.08
采纳率:43% 等级:12
已帮助:6469人
#include
#include
void main(void)
{
int a,b; //两个乘数
int c; //学生输入的答案
while(true)
{
a = rand() % 10 + 1;
b = rand() % 10 + 1;
printf("%d * %d = ?\n", a, b);
scanf("%d", &c);
if(c == a * b)
{
printf("Right!\n");
}
else
{
//再给三次机会
int chance = 3;
while(chance > 0)
{
printf("Wrong! Please try again.\n");
scanf("%d", &c);
if(c == a * b)
{
printf("Right!\n");
break;
}
chance --;
}
//三次都不对,程序结束
if(chance == 0)
{
printf("Wrong! You have tried three times! Test over!\n");
return ;
}
}
}
}
20分享举报