#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Main ()
{
int a,b,c,n,u,i,sum;
int resulttrue=0;
int answer;
int time;
Char op,op2;
do//Generating Random numbers
{
A=rand ()%100+1;
B=rand ()%100+1;
C=rand ()%100+1;
N=rand ()%4+1;
U=rand ()%4+1;
Switch (n)
{
Case 1://contains an operator
{
Switch (u%4)//Generation operator
{
Case 0:
{
op= ' + ';
Break
}
Case 1:
{
op= '-';
Break
}
Case 2:
{
op= ' * ';
Break
}
Case 3:
{
op= '/';
Break
}
}
printf ("%d%c%d=\n", a,op,b);//Print
Switch (OP)//Calculate answer by operator
{
Case ' + ':
{
Resulttrue=a+b;
Break
}
Case '-':
{
Resulttrue=a-b;
Break
}
Case ' * ':
{
Resulttrue=a*b;
Break
}
Case '/':
{
resulttrue=a/b;
Break
}
}
while (time<121)
{
printf ("Please enter the correct answer (time is two minutes):");
scanf ("%d", &answer);
if (time==120)
{
printf ("Time is up, can't answer \ n");
time=0;
Break
}
if (time<120)
{
if (answer==resulttrue)
{
printf ("Correct answer \ n");
Break
}
Else
{
printf ("Wrong answer \ n");
Break
}
}
}
}
Case 2://produces two operators
{
Switch (u%4)//The first operator produces a
{
Case 0:
{
op= ' + ';
Break
}
Case 1:
{
op= '-';
Break
}
Case 2:
{
op= ' * ';
Break
}
Case 3:
{
op= '/';
Break
}
}
Switch (u%4)//The second operator produces
{
Case 0:
{
Op2= ' + ';
Break
}
Case 1:
{
Op2= '-';
Break
}
Case 2:
{
op2= ' * ';
Break
}
Case 3:
{
op2= '/';
Break
}
}
printf ("%d%c%d%c%d=\n", a,op,b,op,c);//Print
Switch (OP)//Calculate the answer first by calculating the first operator
{
Case ' + ':
{
Sum=a+b;
Break
}
Case '-':
{
Sum=a-b;
Break
}
Case ' * ':
{
Sum=a*b;
Break
}
Case '/':
{
sum=a/b;
Break
}
}
Switch (OP2)//And then based on the second operator
{
Case ' + ':
{
Sum=sum+c;
Break
}
Case '-':
{
Sum=sum-c;
Break
}
Case ' * ':
{
Sum=sum*c;
Break
}
Case '/':
{
SUM=SUM/C;
Break
}
}
while (time<123)//Time setting
{
printf ("Please enter the correct answer (time is two minutes):");
scanf ("%d", &answer);
if (time==120)
{
printf ("Time is up, can't answer \ n");
time=0;
Break
}
if (time<120)
{
if (answer==sum)
{
printf ("Correct answer \ n");
Break
}
Else
{
printf ("Wrong answer \ n");
Break
}
}
}
}
}
}while (1);
}
201306114357-Experimental 3-c language