use **standard C++**

Write a program named, mathTrainer*.cpp*. This program will help a young math student practice the four basic operations. This program begins by displaying for the user a menu of choices. The choices will be either to create a random problem for one of the four operations or to quit the application. You can see from the example execution log for Math Trainer that the menu consists of choices that allow the user to have the program create a problem or quit.

Here are more specific requirements for the different options.

Addition Problems

– Both operands should be random numbers in the range, 1 to 500, inclusive.

– Use the ‘+’ as the addition operator symbol

Subtraction Problems

– Both operands should be random numbers in the range, 1 to 999, inclusive

– But the second operand, (the number being subtracted from the top number) should be less than or equal to the first operand

This ensures that the answers to subtraction problems are never negative

– Use the ‘-‘ as the subtraction operator symbol

Multiplication Problems

– The first operand (top number) must be in the range of 1 to 100, inclusive.

– The second operand (bottom number) must be in the range of 1 to 9, inclusive.

– Use the ‘X’ as the multiplication operator symbol

Division Problems

– Display these problems horizontally as: Operand1 / Operand2 = , a.k.a, Dividend / Divisor =

– The range for the divisor (operand 2) must be from 1 to 9, inclusive

– The dividend (operand 1) must have a value such that the resulting quotient is always in the range of 1 to 50, inclusive

Remember to use named constants (const) for all hard values found in the requirements or implied by them. In this program all of the minimum and maximum range values should be named constants.

Notes: Make sure you generate numbers in the proper range. Test your program to see that you generate*different* numbers each time. This is accomplished by seeding the generator each time the program runs. Make sure your output is formatted like the examples given above.

## Expert Answer

**The code for mathTrainer.cpp is given below with sample output screens :**

**mathTrainer.cpp**

#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <ctime>

using namespace std;

void add(double n1,double n2);

void sub(double n1,double n2);

void mult(double n1,double n2);

void div(double n1,double n2);

int main(int nNumberofArgs,char* pszArgs[])

{

int n1,n2;

int choice;

cout << “Welcome to the math Trainer” << endl;

for(;;)

{

cout << “Enter a number choice of your own : ” << endl;

cout << “1 – Addition” << endl;

cout << “2 – subraction” << endl;

cout << “3 – multplication” << endl;

cout << “4 – division” << endl;

cout << “5 – Exit” << endl;

cout << endl << “Choice: “;

cin >> choice;

if(cin.fail())

{

cout << “Invalid answer, now its quitting ” << endl;

system(“PAUSE”);

return 0;

}

srand((unsigned)time(0));

n1 = rand() % 100 + 1;

n2 = rand() % 100 + 1;

switch(choice)

{

case 1:

add(n1,n2);

break;

case 2:

sub(n1,n2);

break;

case 3:

mult(n1,n2);

break;

case 4:

div(n1,n2);

break;

case 5:

cout << “Thanks a lot for playing the Trainer ” << endl;

system(“PAUSE”);

return 0;

default:

cout << “Invalid Number!” << endl;

system(“PAUSE”);

return 0;

}

}

}

void add(double n1,double n2)

{

double answer;

cout << “What is ” << n1 << ” + ” << n2 << “?” << endl;

cout << “Answer: “;

cin >> answer;

if(answer == n1 + n2)

{

cout << endl << “Correct!” << endl << endl;

}

else

{

cout << endl << “Wrong! The right answer was ” << n1 + n2 << endl << endl;

}

}

void sub(double n1,double n2)

{

double answer;

cout << “What is ” << n1 << ” – ” << n2 << “?” << endl;

cout << “Answer: “;

cin >> answer;

if(answer == n1 – n2)

{

cout << endl << “Correct!” << endl << endl;

}

else

{

cout << endl << “Wrong! The right answer was ” << n1 * n2 << endl << endl;

}

}

void mult(double n1,double n2)

{

double answer;

cout << “What is ” << n1 << ” * ” << n2 << “?” << endl;

cout << “Answer: “;

cin >> answer;

if(answer == n1 * n2)

{

cout << endl << “Correct!” << endl << endl;

}

else

{

cout << endl << “Wrong! The right answer was ” << n1 * n2 << endl << endl;

}

}

void div(double n1,double n2)

{

double answer;

double r = n1 / n2;

cout << “What is ” << n1 << ” / ” << n2 << “?” << endl;

cout << “Remember that your answer must only have 6 numbers in it, round” << endl;

cout << “0 does not count as a number, remember to do 0.123 etc.” << endl;

cout << “Answer: “;

cin >> answer;

if(answer == r)

{

cout << endl << “Correct!” << endl << endl;

}

else

{

cout << endl << “Wrong! The right answer was ” << r << endl << endl;

}

}

**sample output :**