少年,写好了,给你参考一下。还可以更复杂。
#include
#include
#include
#define N 10
int Test()
{
int num = 0;
int answer = 0;
int result = 0;
int m = 0;
int n = 0;
char op = 0;
int count = N;
while ( count-- )
{
m = rand() % 10;
n = rand() % 10;
op = rand() % 4;
switch ( op )
{
case 0:
op = '+';
answer = m+n;
break;
case 1:
op = '-';
answer = m-n;
break;
case 2:
op = '*';
answer = m*n;
break;
case 3:
n++;
op = '/';
answer = m/n;
break;
default:
break;
}
printf("\n题目:");
printf("%d%c%d=?\n", m, op, n);
printf("请输入答案:");
scanf("%d", &result);
if ( answer == result )
num++;
}
return num;
}
int main()
{
srand( time(NULL) );
printf("开始做题:\n");
printf("答题结束,你总共答对%d道题目。\n", Test());
return 0;
}
#include
#include
void main()
{
int a,b;
int add,sub,pro,div;
int num;
int oper;
int answer;
for(int i=0;i<10;i++) //定义出题为10个
{
a=rand()%10;
b=rand()%10;
oper=rand()%4;
switch(oper)
{
case 1:
{
printf("请输入答案:\n");
printf("%d + %d =",a,b);
scanf("%d",&answer);
if((a+b)==answer)
{
printf("\n回答正确,请继续\n");
}
}
case 2:
{
printf("请输入答案:\n");
printf("%d - %d =",a,b);
scanf("%d",&answer);
if((a-b)==answer)
{
printf("\n回答正确,请继续\n");
}
}
case 3:
{
printf("请输入答案:\n");
printf("%d * %d =",a,b);
scanf("%d",&answer);
if((a*b)==answer)
{
printf("\n回答正确,请继续\n");
}
}
case 4:
{
printf("请输入答案:\n");
printf("%d / %d =",a,b);
scanf("%d",&answer);
if((a/b)==answer)
{
printf("\n回答正确,请继续\n");
}
}
}
}
}
只要流程?