#include <stdlib.h>
#define N 10
main()
{long num1,num2,result;
int yunsuan,i,right=0,wrong=0;
for(i=1;i<=N;i++)
{num1=rand();
num2=rand();
yunsuan=rand()%4+1;
switch(yunsuan)
{case 1:printf("%ld + %ld = ",num1,num2);
scanf("%ld",&result);
if(result==(num1+num2))
printf("right\n",right++);
else
printf("wrong\n",wrong++);
break;
case 2:printf("%ld - %ld = ",num1,num2);
scanf("%ld",&result);
if(result==(num1-num2))
printf("right\n",right++);
else
printf("wrong\n",wrong++);
break;
case 3:printf("%ld * %ld = ",num1,num2);
scanf("%ld",&result);
if(result==(num1*num2))
printf("right\n",right++);
else
printf("wrong\n",wrong++);
break;
case 4:printf("%ld / %ld = ",num1,num2);
scanf("%ld",&result);
if(result==(num1/num2))
printf("right\n",right++);
else
printf("wrong\n",wrong++);
}
}
clrscr();
printf("\n------------------------------------------\n%d right....%d wrong\n------------------------------------------\n",right,wrong);
printf("\nyou score is %2.2f",(float)(right)/(float)(N)*100);
getch();
}
楼主看看我写的这个是不是你想要的?其中N是题目数量。。。
[此贴子已经被作者于2006-12-31 15:10:19编辑过]