1#include <iostream>2#include <ctime>3 using namespacestd;4 5 voidMain ()6 {7 inta,b,c;8Srand (Unsigned (Time (NULL)));//change of the guaranteed number of random seed with system time9 for(intI=0;i< -; i++)Ten { OneA=rand ()% About+1; AB=rand ()% About+1; -C=rand ()%4+1; - Switch(c) the { - Case 1:cout<<a<<"+"<<b<<"="<<endl; Break; - Case 2:{ - if(A>B)//use the IF statement to ensure that Minuend is greater than +cout<<a<<"-"<<b<<"="<<Endl; - Else +cout<<b<<"-"<<a<<"="<<Endl; A Break; at } - Case 3:cout<<a<<"*"<<b<<"="<<endl; Break; - Case 4:cout<<a<<"/"<<b<<"="<<endl; Break; - } - } -}
Idea: The random number function is used to randomly generate an integer between two and 1-99, the operator is randomly selected by the method of redundancy, and the output is finally used for loop. In order to ensure that minuend is greater than the use of the IF statement to judge, the entire output statement also uses the switch statement for conditional output.
Class time failed to complete reason: Generate random number function forget how to use.
Introduction to Software engineering the first classroom quiz-------to produce a small program of random integer arithmetic of 30 100 or less