Four arithmetic question generator (C ++) and four arithmetic question Generator
Question: Four arithmetic question generator.
Idea: Use the rand () % 100 function to generate a random positive integer of less than 100. Likewise, use the random function rand () % 4 to generate random 0, 1, 2 and 3 are random integers corresponding to the four conditions of addition, subtraction, multiplication, and division. This program numbers the question and can customize the number of questions to automatically remove the illegal situation where the divisor is 0.
Code:
# Include <iostream. h>
# Include <stdlib. h>
# Include <time. h>
Int num (int x)
{
Return rand () % 100;
}
Int fh ()
{
Return rand () % 4;
}
Int main ()
{
Int a, I, j, n;
Cout <"~~~~~~~~~~~~~~~~~~ "<" Please leave your homework rationally! "<"~~~~~~~~~~~~~~~~~ "<" \ N ";
Cout <"Enter the number of questions :";
Cin>;
Srand (time (NULL ));
While (1)
{
If (a <1)
{
Cout <"incorrect input. Please enter again :";
Cin>;
}
Else
{
For (j = 0; j <a; j ++)
{
I = fh ();
Switch (I)
{
Case 0:
Cout <j + 1 <":" <"" <num (1) <"+" <num (2) <"=" <"\ n ";
Break;
Case 1:
Cout <j + 1 <":" <"" <num (1) <"-" <num (2) <"=" <"\ n ";
Break;
Case 2:
Cout <j + 1 <":" <"" <num (1) <"*" <num (2) <"=" <"\ n ";
Break;
Case 3:
N = num (2 );
If (n! = 0)
{
Cout <j + 1 <":" <"" <num (1) <"/" <n <"=" <"\ n ";
}
Else
{
J --;
}
Break;
}
}
Break;
}
}
Return 0;
}