#include
#include
#include
int Makenumber(void);
int Countnumber(void);
char Op(void);
int a,b,t;
float result1,result2;
int main()
{
char reply;
srand(time(NULL));
do{
int i=1,counter=0;
do{
Makenumber();
Op();
Countnumber();
i++; //循环变量//
if(result1==result2)
{
printf("right!next!\n");
counter++; //答对的次数//
}
else
printf("wrong!\n");
}while(i<=10);
printf("you get %d marks!\n",counter*10);
printf("The correct answer rate was %d%%.\n",counter*10);
printf("\n");
printf("Do you want to continue(Y/N or y/n)?\n");
scanf(" %c",&reply); //%c前面空一个格//
}while(reply=='y'||reply=='Y');
return 0;
}
int Makenumber(void)
{
a=rand()%10+1;
b=rand()%10+1;
return 0;
}
char Op(void)
{
t=rand()%4+1;
switch(t)
{
case 1:
result1=a+b;
break;
case 2:
result1=a-b;
break;
case 3:
result1=a*b;
break;
case 4:
result1=a/b;
break;
}
return result1;
}
int Countnumber(void)
{
switch(t)
{
case 1:
printf("please compute%d+%d=",a,b);
scanf("%f",&result2);
break;
case 2:
printf("please compute%d-%d=",a,b);
scanf("%f",&result2);
break;
case 3:
printf("please compute%d*%d=",a,b);
scanf("%f",&result2);
break;
case 4:
printf("please compute%d/%d=",a,b);
scanf("%f",&result2);
break;
}
return result2;
}