Present the following menu to your user and ask them what ki

Present the following menu to your user and ask them what kind of math problem they want to solve: Math Tutor Menu Addition Problem Subtraction Problem Multiplication Problem Random Problem Enter your choice: The first option should generate two random values between 0 and 100, and ask the user for the sum of the two numbers. Display whether or not the user got the question correct. The second option should generate two random values between 0 and 100, and ask the user for the difference of the two numbers. Display whether or not the user got the question correct. The third option should generate two random values between 0 and 100, and ask the user for the product of the two numbers. Display whether or not the user got the question correct. The fourth option should generate two random values between 0 and 100, and then randomly choose which math operation (addition, subtraction, or multiplication) to perform on those two numbers.

Solution

// C++ code

#include <iostream>
#include <stdlib.h>
using namespace std;


int menu()
{
   int choice;
   cout << \"\ Math Tutr Menu\ 1. Addition Problem\ 2. Subtraction Problem\ \";
   cout << \"3. Multiplication Problem\ 4. Random problem\ 5. Quit\ \";
   cout << \"Enter your choice: \";
   cin >> choice;

   return choice;
}

void add()
{
   int number1, number2;
   number1 = rand()%100;
   number2 = rand()%100;
   int sum = number1 + number2;
   int userInput;

   cout << number1 << \"+\" << number2 << \" = \";
   cin >> userInput;

   if(userInput == sum)
   {
       cout << \"Correct answer\ \ \";
   }
   else
   {
       cout << \"Incorrect answer\ \";
       cout << \"Correct answer: \" << sum << endl;
   }
}

void subtract()
{
   int number1, number2;
   number1 = rand()%100;
   number2 = rand()%100;
   int difference = number1 - number2;
   int userInput;

   cout << number1 << \"-\" << number2 << \" = \";
   cin >> userInput;

   if(userInput == difference)
   {
       cout << \"Correct answer\ \ \";
   }
   else
   {
       cout << \"Incorrect answer\ \";
       cout << \"Correct answer: \" << difference << endl;
   }
}

void multiply()
{
   int number1, number2;
   number1 = rand()%100;
   number2 = rand()%100;
   int product = number1 * number1;
   int userInput;

   cout << number1 << \"*\" << number2 << \" = \";
   cin >> userInput;

   if(userInput == product)
   {
       cout << \"Correct answer\ \ \";
   }
   else
   {
       cout << \"Incorrect answer\ \";
       cout << \"Correct answer: \" << product << endl;
   }
}

int main()
{
   int choice;
   time_t t;
   srand((unsigned) time(&t));

   while(true)
   {
       choice = menu();

       if(choice == 1)
       {
           add();
       }
       else if(choice == 2)
       {
           subtract();
       }
       else if(choice == 3)
       {
           multiply();
       }
       else if(choice == 4)
       {
           int r = rand()%3+1;
           if(r == 1)
               add();
           else if(r == 2)
               subtract();
           else if(r == 3)
               multiply();
       }
       else
           break;
   }
}

/*
output:

Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 1
56+89 = 113
Incorrect answer
Correct answer: 145


Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 2   
1-32 = -31
Correct answer


Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 3
41*38 = 4564
Incorrect answer
Correct answer: 1681

Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 4
70+89 = 159
Correct answer


Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 4
74*73 = 4945
Incorrect answer
Correct answer: 5476

Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 4
26+24 = 52
Incorrect answer
Correct answer: 50

Math Tutr Menu
1. Addition Problem
2. Subtraction Problem
3. Multiplication Problem
4. Random problem
5. Quit
Enter your choice: 5


*/

 Present the following menu to your user and ask them what kind of math problem they want to solve: Math Tutor Menu Addition Problem Subtraction Problem Multipl
 Present the following menu to your user and ask them what kind of math problem they want to solve: Math Tutor Menu Addition Problem Subtraction Problem Multipl
 Present the following menu to your user and ask them what kind of math problem they want to solve: Math Tutor Menu Addition Problem Subtraction Problem Multipl
 Present the following menu to your user and ask them what kind of math problem they want to solve: Math Tutor Menu Addition Problem Subtraction Problem Multipl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site