// Name: Alan Helms // Class: CPT 232 C++ I // Times: MWF 9:00 - 9:50 // Semester: Spring 3-14-2003 // Project Name: TenQs_vfx.cpp // Program Purpose: This program is a 30 second math quiz. The program uses // three functions which, one function returns one random number // 1 - 12, another returns one random character: +, -, *, /, %. // The last function returns a result, which depends on the // previous two functions. The timing feature uses the // rand() function, also the header file . These // function generate either random integers or random characters. // The values that are generated are used to ouput an // mathematical expression which the user is to provide an answer. // That answer is checked with the result of the third function. // There is also a counter to keep record of the number question // that were answered correctly. // // // ****NOTE: THIS VERSION WAS CREATED WITH Microsoft Visual C++ EDITIOR**** #include using std::cin; using std::cout; using std::endl; #include using std::setprecision; using std::setiosflags; using std::setw; using std::ios; #include #include // The prototype for CalAnswer() function int CalAnswer ( int, char, int); // The prototype for RandNUM() function. int RandNUM (int); // The prototype for RandSIGN() function. char RandOPS (int); // The main program. int main() { int answer, nCorrect = 0; char yes_NO; cout << "Welcome to BRAIN STRAIN THE MATH GAME.\n\n" << "BRAIN STRAIN is a 30 second arithmetic quiz.\n" << "Your objective is to answer as many questions\n" << "correctly as you can within time allowed.\n" << "**NOTE: \"/\" means integer division, \"%\" means\n" << "modulus." << endl << endl; srand(time(0)); cout << "To begin the quiz press \"y\". "; cin >> yes_NO; if (yes_NO == 'y'|| yes_NO == 'Y') { int startTime = time(0); // timer mechanism for (int timer = 0; time(0) - startTime < 36; ++timer) { int rNum1, rNum2; char rOpr1; // set the value randomly generated to a variable // then the variable is passed to the CalAnswer() function. rNum1 = RandNUM(rand()); // call for the RandNUM() Function. rOpr1 = RandOPS(rand()); // call for the RandOPS() Function. rNum2 = RandNUM(rand()); // call for the RandNUM() Function. cout << rNum1 << " " << rOpr1 << " " << rNum2 << " = "; cin >> answer; cout << endl; // the variables are passed into the CalAnswer() function // and checked against the user supplied answer. if ( CalAnswer(rNum1, rOpr1, rNum2) == answer) { cout << "Correct!!" <