# include
# include
# include
using namespace std;
Const int N=10;
Double the add (int min, int Max, int n);
Double sub (int min, int Max, int n);
Double the mul (int min, int Max, int n);
Double div (int min, int Max, int n);
Void main ()
{
Srand ((unsigned) time (NULL));//initializes the random number generator
Int imin, imax, k;
double s;
Char ch='1';
While (ch!='0');
{
Cout<& lt;" \ t -- -- -- -- -- -- -- -- -- elementary arithmetic trainers -- -- -- -- -- -- -- -- -- \ n ";
Cout<& lt;" \ n please select operation type ";
Cout<& lt;" \ n \ n ";
Cout<& lt;" \ \ t t0. \ n "end & lt; & lt;" \ \ t t1. \ n an addition operation "& lt; & lt;" \ \ t t2. Subtract \ n
"<& lt;" \ \ t t3. The multiplication \ n "& lt; & lt;" \ \ t t4. Division \ n ";
Cout<& lt;" T \ \ t please select (0 to 4) : ";
Ch=getch ();
While (ch=='0') break;
While (ch> '4') continue;
Cout<& lt;" \ n \ n ";
Cout<& lt;" \ n please choose the type of operand range: ";
Cout<& lt;" \ n \ n ";
Cout<& lt;" T \ \ n \ t1 0-9 \ n "& lt; & lt;" \ \ t t2 0-99 \ n "& lt; & lt;" \ \ t t3 0-999 \ n "& lt; & lt;" \ \ t t4 0-9999 \ n ";
Cin> k;
The switch (k)
{
Case 1: imin=0, imax=9; break;
Case 2: imin=0, imax=99; break;
Case 3: imin=0, imax=999; break;
Case 4: imin=0, imax=9999; break;
}
The switch (ch)
{
Case '1' ://add
S=add (imin, imax, N); break;
Case '2' ://subtract
S=sub (imin, imax, N); break;
Case '3' ://multiplication
S=the mul (imin, imax, N); break;
Case '4' ://division
S=div (imin, imax, N); break;
}//
Cout<& lt;" The test score: "& lt;
}
While (ch!='0');
}
Double the add (int min, int Max, int n)
{
Int a, b, c, ans, ok=0;
for(int i=0; i
A=rand () % (Max - min + 1) + min;
B=rand () % (Max - min + 1) + min;//calculate the standard answer, according to the title, the user answer
C=a + b;
Cout<& lt;" The first "& lt; Cin> Ans.
for(int j=0; j<2; J++)
{
If (ans!=c)
{
Cout<& lt;" The answer wrong, please input again!" <& lt;" \ t "& lt; & lt;" The first "& lt; Cin> Ans.
}
The else
Ok++; continue;
}
If (ans!=c)
Cout<& lt;" The correct result to "& lt;
Return ok * 10.0/2;
}
Double sub (int min, int Max, int n)
{
Int a, b, c, ans, ok=0;
for(int i=0; i
B=rand () % (Max - min + 1) + min;
If (aA, c=a=b, b=c.//calculate the standard answer, according to the title, the user answer
C=a - b;
Cout<& lt;" The first "& lt; Cin> Ans.
for(int j=0; j<2; J++)
{
If (ans!=c)
{
Cout<& lt;" The answer wrong, please input again!" <& lt;" \ t "& lt; & lt;" The first "& lt; Cin> Ans.
}
The else
Ok++; continue;
}
If (ans!=c)
Cout<& lt;" The correct result to "& lt;
Ok/return 10.0 * 2;
}
Double the mul (int min, int Max, int n)
{
Int a, b, c, ans, ok=0;
for(int i=0; i
A=rand () % (Max - min + 1) + min;
B=rand () % (Max - min + 1) + min;//calculate the standard answer, according to the title, the user answer
C=a * b;
Cout<& lt;" The first "& lt; Cin> Ans.
for(int j=0; j<2; J++)
{
If (ans!=c)
{
Cout<& lt;" The answer wrong, please input again!" <& lt;" \ t "& lt; & lt;" The first "& lt; Cin> Ans.
}
The else
Ok++; continue;
}
If (ans!=c)
Cout<& lt;" The correct answer is "& lt;
Ok/return 10.0 * 2;
}
Double div (int min, int Max, int n)
{
Int a, b, c, ans, ok=0;
for(int i=0; i
//have two operands
Do
{
A=rand () % (Max - min + 1) + min;
B=rand () % (Max - min + 1) + min;
If (a==0) a +=1;
If (b==0) b +=1;
If (a{
c=a;
a=b;
B=c.
}
}
While (a % b!=0);//calculate the standard answer, according to the topic, the user answer,
c=a/b;
Cout<& lt;" The first "& lt; Cin> Ans.
for(int j=0; j<2; J++)
{
If (ans!=c)
{
Cout<& lt;" The answer wrong, please input again!" <& lt;" \ t "& lt; & lt;" The first "& lt; "Cin> Ans.
}
The else
Ok++; continue;
}
If (ans!=c)
Cout<& lt;" The correct result to "& lt;
Ok/return 10.0 * 2;
}