先选择运算,包括加法,减法乘法除法四种选项
选择一种运算进入做题,可以选择难易程度,简单是十以内运算,难是一百以内运算
然后进入做题,系统会随机出题
输入答案,系统会判断对错,然后又四个选项。
退出系统会显示做题的数量,与所得的分数
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
int question_get();
int type;
void main()
{
int answer,n,score=0,number=0;
loop: printf("请选择要进行测试的题目种类:");
printf("\n1.加法运算\n2.减法运算\n3.乘法运算\n4.除法运算\n5.退出运算\n");
printf("\t\t请选择(1-5):");
scanf("%d",&type);
while(type>0&&type<6)
{
int temp;
int flag;
number=number+1;
answer=question_get();
lop:printf("请回答:\n");
scanf("%d",&temp);
if(temp==answer)
{
printf("\n答案正确\n");
score=score+1;
}
else
{
printf("\n答案错误\n");
}
printf("查看答案3,重做请按2,继续请按1,退出请按0\n");
scanf("%d",&flag);
while(flag!=0&&flag!=1&&flag!=2&&flag!=3)
{
printf("按其他键无效\n");
scanf("%d",&flag);
}
if(flag==0)
{
printf("做的题目数量%d\n",number);
printf("得分%d\n",score);
break;
}
else
{
if(flag==1)
goto loop;
else
{
if(flag==2)
goto lop;
else
if(flag==3)
{
printf("正确答案%d\n",answer);
goto loop;
}
}
}
}
}
int question_get()
{
int a,b,c;
int amount;
loop:if(type==1)
{
printf("请选择难易程度\n");
printf("简单请按0,困难请按1\n");
scanf("%d",&amount);
while(amount!=0&&amount!=1)
{
printf("按其他键无效\n");
scanf("%d,&amount");
}
if(amount==0)
{
a=rand()%8;
b=9-a;
b=rand()%b;
printf("%d+%d=?",a,b);
return(a+b);
}
else
{
a=rand()%99;
b=100-a;
b=rand()%b;
printf("%d+%d=?",a,b);
return(a+b);
}
}
else
if(type==2)
{
printf("请选择难易程度\n");
printf("简单请按0,困难请按1\n");
scanf("%d",&amount);
while(amount!=0&&amount!=1)
{
printf("按其他键无效\n");
scanf("%d,&amount");
}
if(amount==0)
{
a=rand()%7;
b=9-a;
b=rand()%b;
printf("%d-%d=?",a+b,b);
return(a);
}
else
{
a=rand()%97;
b=99-a;
b=rand()%b;
printf("%d-%d=?",a+b,b);
return(a);
}
}
else
if(type==3)
{
printf("请选择难易程度\n");
printf("简单请按0,困难请按1\n");
scanf("%d",&amount);
while(amount!=0&&amount!=1)
{
printf("按其他键无效\n");
scanf("%d,&amount");
}
if(amount==0)
{
a=rand()%4;
b=6-a;
b=rand()%b;
printf("%d*%d=?",a,b);
return(a*b);
}
else
{
a=rand()%18;
b=20-a;
b=rand()%b;
printf("%d*%d=?",a,b);
return(a*b);
}
}
else
if(type==4)
{
printf("请选择难易程度\n");
printf("简单请按0,困难请按1\n");
scanf("%d",&amount);
while(amount!=0&&amount!=1)
{
printf("按其他键无效\n");
scanf("%d,&amount");
}
if(amount==0)
{
a=rand()%4;
b=6-a;
b=1+rand()%b;
printf("%d/%d=?",a*b,b);
return(a);
}
else
{
a=rand()%18;
b=20-a;
b=1+rand()%b;
printf("%d/%d=?",a*b,b);
return(a);
}
}
while(type==0&&type>5)
{
printf("输入错误\n");
printf("请输入1-5\n");
scanf("%d",&type);
goto loop;
}
}