1, the title requirements: In addition to integers, but also to support the true score of the arithmetic.
2, design ideas:
(1) The production of the operand:
A. Define a random function with a macro definition.
B. Random random functions are used to generate random numbers and define the range of values for random numbers.
(2) Operator problem Resolution:
A. Invoking random functions to generate 0~3 four random numbers
B. Quote Swatch, case structure, randomly select operation symbol: 0: Add 1: minus 2: Multiply 3: except
(3) Output of the running result:
Use the For loop structure to output 30 arithmetic titles sequentially and display them on the screen.
(4) Unresolved issues:
The problem of random generation of true fractional calculation is not solved, and it is hoped that the future efforts can solve this problem.
3. SOURCE program code:
Random generation of arithmetic topics within 30 100
Hu Haote 2016/3/5
#include <iostream>
using namespace Std;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RANDOM (x) (rand ()%x)
int main ()
{
int I, a, b;
int mode = 0,result=0;//0: plus 1: minus 2: Multiply by 3: except
for (i = 0; i<30; i++)//randomly generate 30 questions
{
A = random (100); Generates a random number between 0~99
b = Random (100); Generates a random number between 0~99
mode = random (4); Generates a random number between 0~3, which represents the operator
cout<< A; Print calculation
switch (mode)//OK operator
{
Case 0:
cout<< "+";
result = a + B;
Break
Case 1:
cout<< "-";
result = A-B;
Break
Case 2:
cout<< "*";
result = A * b;
Break
Case 3:
cout<< "/";
result = A/b;
Break
Default
cout<< "Somethingis wrong!\n";
Break
}
cout<< b<< "=" <<endl;
}
return 0;
}
Random generation of arithmetic topics within 30 100