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 #include // For rand and srand #include // For the time function #include using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!