Page 1 of 1

Update your Math program to include: As in the previous iteration, the program should show the menu again after the use

Posted: Thu Jul 14, 2022 2:06 pm
by answerhappygod
Update your Math program to include:
As in the previous iteration, the program should show the menuagain after the user gets the problem correct or three incorrectattempts. Be sure to include an option to Quit in the menu.
HINT:
pseudocode for function definition for addition:
void addition()
{
// be sure to declare localvariables in the function such as
// int num1, num2, min, max,answer, result;
// add your logic here
}
THIS IS MY CODE THAT NEEDS TO BE UPDATED
#include<iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <ctime>
#include <iomanip>
using namespace std;
int main() {
string name;
int num1, num2 = 0, result = 0,answer, min1, max1 = 0, min2, max2;
char choice = 0 ;
const string ERROR = "Invalidchoice, Please choose a given option.";
const string QUIT_1= "Thankyou,",
QUIT_2 = " , for using this program! Please use itagain if you need more practice!\n\n";
cout << "Hello, what is your name?" <<endl;
getline(cin, name);
cout << "\n\nWelcome, "<< name<<" to Math Tutor!" <<endl << "I will help youtest your simple addition, subtraction, multiplication or divisionskills." << endl;
cout << endl << "Which do you wish topractice?"<< endl;
cout << "1.Addition" << endl;
cout << "2.Subtraction" << endl;
cout << "3.Multiplication" <<endl;
cout << "4.Division" << endl;
cout << "5.Quit"<< endl <<endl;
cin >> choice;
cout << choice;
while (choice != '1' &&choice != '2' && choice != '3' && choice != '4'&& choice != '5')
{
cout << " That option is not available,please try again";
cin >> choice;
}
switch (choice)
{
case '1':
min1 = 100;
max1 = 999;
num1 = (rand()% (max1- min1 + 1)) + min1;
min2 = 10;
max2 = 99;
num2 = (rand() % (max2- min2 + 1)) + min2;
result = num1 +num2;
cout << " Youhave chosen Addition" << endl;
cout << endl<< "Input your answer." << endl;
cout << setw(5)<< num1 << endl;
cout << "+ " << num2 << endl;
cout << " " << endl;
cin >>answer;
if(answer == result)
{
cout<< "\n Excellent, " << name << "! You arecorrect. \n\n;";
}
elseif (answer != result)
{ cout << "\nNope. Thats not correct, " << name << ". The correctanswer is " << result << ".\nReview your notes and tryagain." << endl << endl;
}
break;
case'2':
min1 = 10;
max1 = 99;
num1 = (rand()% (max1- min1 + 1)) + min1;
min2=1;
max2=9;
num2 = (rand() % (max2- min2 +1)) + min2;
result = num1 -num2;
cout << " Youhave chosen Subtraction" << endl;
cout << endl<< "Input your answer." << endl;
cout << setw(5)<< num1 << endl;
cout << "- " << num2 << endl;
cout << " " << endl;
cin >>answer;
if(answer == result)
{
cout<< "\n Excellent, " << name << "! You arecorrect. \n\n;";
}
elseif (answer != result)
{ cout << "\nNope. Thats not correct, " << name << ". The correctanswer is " << result << ".\nReview your notes and tryagain." << endl << endl;
}
break;
case '3':
min1 = 1;
max1 = 12;
num1 = (rand()% (max1- min1 + 1)) + min1;
min2=1;
max2=12;
num2 = (rand() % (max2- min2 +1)) + min2;
result = num1 *num2;
cout << " Youhave chosen Multiplication" << endl;
cout << endl<< "Input your answer." << endl;
cout << setw(5)<< num1 << endl;
cout << "* " << num2 << endl;
cout << " " << endl;
cin >>answer;
if(answer == result)
{
cout<< "\n Excellent, " << name << "! You arecorrect. \n\n;";
}
elseif (answer != result)
{
cout<< "\n Nope. Thats not correct, " << name << ".The correct answer is " << result << ".\nReview yournotes and try again." << endl << endl;
}
case'4':
min1 =10;
min2 =999;
num1 =(rand()% (max1 - min1 + 1)) + min1;
cout<< " You have chosen Division" << endl;
cout << endl<< "Input your answer." << endl;
cout << setw(5)<< num1 << endl;
cout << "/ " << num2 << endl;
cout << " " << endl;
cin >>answer;
if(answer == result)
{
cout<< "\n Excellent, " << name << "! You arecorrect. \n\n;";
}
elseif (answer != result)
{ cout << "\nNope. Thats not correct, " << name << ". The correctanswer is " << result << ".\nReview your notes and tryagain." << endl << endl;
min2 =1;
max2 =9;
num2 =(rand()% (max2 - min2 +1 )) + min2;
result =num1 / num2;
case'5':
cout<< "\nYou chose to quit the program. " << endl <<endl;
break;
default:
cout<< ERROR << endl;
break;
}
cout << QUIT_1<< name << QUIT_2 << endl;
system("pause");
}
return 0;
}