Question: Modify the program again so it displays a menu allowing the user to select an addition, subtraction, multiplication, or division problem. The final selection on
Modify the program again so it displays a menu allowing the user to select an addition, subtraction, multiplication, or division problem. The final selection on the menu should let the user quit the program. After the user has finished the math problem, the program should display the menu again. This process repeated until the user chooses to quit the program. Input Validation: If the user selects an item not on the menu, display an error message and display the menu again.
C++
#include
int main() { // Constants const int MIN = 50; const int MAX = 450;
// Get the system time. unsigned seed = time(0);
// Seed the random number generator. srand(seed);
// Generate two random numbers. int num1 = MIN + rand() % MAX; int num2 = MIN + rand() % MAX; int answer; // To hold the answer
// Display the addition problem. cout << setw(5) << num1 << endl << "+" << setw(4) << num2 << endl << "----- ";
// Wait for the user to press the Enter key. cout << "Enter to the answer here: "; cin >> answer;
// Calculate the sum. int correctAnswer = num1 + num2;
// Display the answer to the addition problem. cout << (answer == correctAnswer ? " Congratulations! " : " Sorry that is incorrect. ") << "The answer is " << correctAnswer << endl << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
