I just got through writing a Math Tutor program. I would like for it to keep up
ID: 3646079 • Letter: I
Question
I just got through writing a Math Tutor program. I would like for it to keep up with the right and wrong answers and show how many you have of each after you answer each math problem. This is my code:/Math Tutor.
/* 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 finshed the math problem, the program should
display the menu again. This process is 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.*/
#include <math.h>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
//Declaring the variables.
srand(time(NULL));
const int SEED = 999;
int num1;
int num2;
float result;
float answer;
int choice;
//Starting do while loop.
do
{ //Random numbers.
num1 = 1+rand() % SEED;
num2 = 1+rand() % SEED;
//Setting the decimal to two decimal places.
cout << setprecision(2) << fixed << endl;
//Setting the menu.
cout << " MENU " << endl;
cout << " 1. Addition ";
cout << " 2. Subtraction ";
cout << " 3. Multiplication ";
cout << " 4. Division ";
cout << " 5. Quit the program ";
cout << "Welcome to the Math Tutor Boys and Girls!!!" << endl;
cout<< "Please make your selection" << endl;
cin >> choice;
//If there are other selections this restarts the menu.
if (choice <= 0 || choice >= 6)
{
cout << "Not A Correct Choice!!" << endl;
cout << " MENU " << endl;
cout << " 1. Addition ";
cout << " 2. Subtraction ";
cout << " 3. Multiplication ";
cout << " 4. Division ";
cout << " 5. Quit the program ";
cout << "Welcome to the Math Tutor Boys and Girls!!!" << endl;
cout<< "Please make your selection" << endl;
cin >> choice;
}
switch (choice)
{ //Adding option.
case 1: cout << num1 << " + " << num2 << " = " << endl;
result = num1 + num2;
break;
//Subtraction option.
case 2: cout << num1<< " - " << num2 << " = " << endl;
result = num1 - num2;
break;
//Multiplication option.
case 3: cout << num1 << " * " << num2 << " = " << endl;
result = num1 * num2;
break;
//Division option.
case 4: cout << num1 << " / " << num2 << " = " << endl;
result = (float)num1 /(float) num2;
break;
//Exit option.
case 5: exit(0);
break;
}
//Input the answer.
cout << "What is your answer?" << endl;
cin >> answer;
answer=ceil(answer*10+0.5)/10;
result=ceil(result*10+0.5)/10;
//Check the answer.
if (answer==result)
cout << "Great Job!!!!!!!!!!!!!!" << endl;
else
cout << "I'm sorry that answer is wrong, the correct answer is " << result << endl;
}while(choice != 5);
return 0;
}