// Demetrios Zeinalipour-Yazti // cs10xx // sec 24,29,30 // lab6 #include #include #include #include #include using namespace std; void main () { // variables declaration int op1, op2; // the two generated operands for each operation int range, addition; // define the range of the generated randoms char type; // the type of output 'x'=multip, '+'=add // initialize the random function generator srand((unsigned)time(0)); // make sure to get the appropriate answer from the user do { cout << "Please select type of question ('x', '+') : "; cin >> type; if (type=='x' || type=='+') { break; } else { cout << "#Error - Only \'x\' & \'+\' are acceptable!\n"; } } while (true); // set the appropriate range // this is the formula for [start..end] // range = (end-start+1) if (type=='x') { // [1..100] range = 100; addition = 1; } else { // [0..12] range = 13; addition = 0; } // generate and output 5 equations for (int i=0; i<5; i++) { // generate 2 operands op1 = (rand() % range) + addition; op2 = (rand() % range) + addition; // output equation cout << setiosflags(ios::left) << setw(5) << op1 << " " << setw(5) << type << " " << setw(5) << op2 << " =\n"; } }