该程序要实现10以内的加减法,并根据题数出题,同时显示最终成绩
#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.text\n");
printf(" 2.practice\n");
printf(" 3.exit\n");
printf("\n please select(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(“score:%d\n”,100*r/ts);
for(i=1;i<ts;i++)
{do{m=num();n=num()}
while(m-n<0||m-n>9);
printf(“%d,%d,%d”,i,m,n);
scanf(“%d”,&s);
if(s==m-n) r++;}
printf("score:%d\n",100*r/ts);
printf("press any key to continue");
getch();
}
numsoftest()
{
int n;
clrscr();
do{
printf("\n please enter the title number(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();}
for(i=1;i<ts;i++)
{do{m=num();n=num();}
while(m-n<0||m-n>9);
printf(“%d,%d,%d”,i,m,n);
scanf(“%d”,&s);
if (s==m-n) right();
else wrong();
}
printf("press any key");
getch();
}
num()
{
return random(9);
}
right()
{
printf("right\n");
}
wrong()
{
printf("error\n");
}
能帮帮忙吗,急啊!!!!!!!!!