#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
for (;;){
switch (menu()){
case '1':test();break;
case '2':practise();break;
case '3':exit(0);
}
}
}
menu()
{
char c;
do{
clrscr();
printf("\n 1.测试\n");
printf(" 2.练习\n");
printf(" 3.退出\n");
printf("\n请选择(1或2或3):");
c=getche();
}while(c<'1'||c>'3');
return c;
}
test()
{
int ts,i,m,n,s,r=0;
ts=numsoftest();
randomize();
for (i=1;i<=ts;i++){
do {
m=num();n=num();
}while ((m+n)>9);
printf("%d) %d+%d=",i,m,n);
scanf("%d",&s);
if (s==m+n) r++;
}
printf("成绩:%d\n",100*r/ts);
printf("按任意键继续...");
getch();
}
numsoftest()
{
int n;
clrscr();
do{
printf("\n请输入题数(10~20):");
scanf("%d",&n);
}while (n<10||n>20);
return n;
}
practise()
{
int ts,i,m,n,s;
ts=numsoftest();
randomize();
for (i=1;i<=ts;i++){
do {
m=num();n=num();
}while ((m+n)>9);
printf("%d) %d+%d=",i,m,n);
scanf("%d",&s);
if (s==m+n) right();
else wrong();
}
printf("按任意键继续...");
getch();
}
num()
{
return random(9);
}
right()
{
printf("正确\n");
}
wrong()
{
printf("错误\n");
}