Question: I need help with my Elementary School Math Practice Program Add enhancements: Input the user's full name, age, grade, and school name Add logic to

I need help with my Elementary School Math Practice Program

Add enhancements:

Input the user's full name, age, grade, and school name

Add logic to track stats including the overall score for each type of math problem (addition, subtraction, multiplication, and division) and an overall score.

Add a function to display stats. This is an option from the Main Menu, so the user can choose it and then continue to play and accumulate stats.

Display Stats: display in a nicely formatted table the user information that was input along with the scores for Addition, Subtraction, Multiplication, Division and Overall Score. Use a percentage format. (For example, solving 5 out of 10 Addition problems is a score of 50%.)

You choose whether to use structs or not. It is not required, but this is a typical example of when a struct can make your code more manageable.

NO GLOBAL VARIABLES OR CONSTANTS. Use parameter passing and local variables and constants.

Current C++ Code:

#include #include #include #include using namespace std;

int displayMenu(); bool isValid(int num, int min, int max); void addition(); void subtraction(); void multiplication(); void division();

int main() { string name; int seed = time(0); srand(seed); int choice;

do { cout << "Welcome to The Math Tutor!" << endl; getline(cin, name);

switch (choice) { case 1: addition(); break; case 2: subtraction(); break; case 3: multiplication(); break; case 4: division(); break; case 5: cout << endl << "Program closing. "; break; default: cout << "Invalid input. "; } } while (choice != 5);

cout << "Have a good day. ";

return 0; }

int displayMenu() { int choice; cout << "Select from the menu which math problems to practice" << endl << "--------------------------------------------------------------------- " << "1. Addition " << "2. Subtraction " << "3. Multiplication " << "4. Division " << "5. Quit Math Tutor " << endl;

cin >> choice;

while (!isValid(choice, 1, 5)) { cin >> choice; }

return choice; }

bool isValid(int num, int min, int max) { if (num < min || num > max) { cout << "Invalid option selected "; cout << "Choose a valid option " << "----------------------------------------- " << "1. Addition " << "2. Subtraction " << "3. Multiplication " << "4. Division " << "5. Quit Math Tutor ";

return false; } else { return true; } }

void addition() { int num1, num2, min, max, answer, result, attempts;

attempts = 3;

min = 2, max = 500, num1 = min + (rand() % (max - min + 1));

min = 1, max = 99, num2 = min + (rand() % (max - min + 1));

while (num2 >= num1) { num2 = min + (rand() % (max - min + 1)); }

result = num1 + num2;

cout << "Addition: you have 3 attempts "; cout << setw(5) << num1 << endl << "+ " << num2 << endl << "______ "; cin >> answer;

while (answer != result && attempts > 0) { cout << "That is not correct. "; cout << attempts << " attempts remaining. "; cout << setw(5) << num1 << endl << "+ " << num2 << endl << "______ "; cin >> answer; attempts--; } if (answer == result) cout << "That is the correct answer. "; else cout << "That is incorrect. The correct answer is " << result << endl; }

void subtraction() { int num1, num2, min, max, answer, result, attempts;

attempts = 3;

min = 2, max = 500, num1 = min + (rand() % (max - min + 1));

min = 1, max = 99, num2 = min + (rand() % (max - min + 1));

while (num2 >= num1) { num2 = min + (rand() % (max - min + 1)); }

result = num1 - num2;

cout << "Subtraction: you have 3 attempts "; cout << setw(5) << num1 << endl << "- " << num2 << endl << "______ "; cin >> answer;

while (answer != result && attempts > 0) { cout << "That is not correct. "; cout << attempts << " attempts remaining. "; cout << setw(5) << num1 << endl << "- " << num2 << endl << "______ "; cin >> answer; attempts--; }

if (answer == result) cout << "That is the correct answer.n"; else cout << "That is incorrect. The correct answer is " << result << endl; }

void multiplication() { int num1, num2, min, max, answer, result, attempts;

attempts = 3;

min = 2, max = 25, num1 = min + (rand() % (max - min + 1));

min = 1, max = 12, num2 = min + (rand() % (max - min + 1));

while (num2 >= num1) { num2 = min + (rand() % (max - min + 1)); }

result = num1 * num2;

cout << "Multiplication: You have 3 attempts. "; cout << setw(5) << num1 << endl << "* " << num2 << endl << "______ "; cin >> answer;

while (answer != result && attempts > 0) { cout << "That is not correct. "; cout << attempts << " attempts remaining. "; cout << setw(5) << num1 << endl << "* " << num2 << endl << "______ "; cin >> answer; attempts--; }

if (answer == result) cout << "That is the correct answer. "; else cout << "That is incorrect. The correct answer is " << result << endl; }

void division() { int num1, num2, min, max, answer, result, attempts;

attempts = 3;

min = 2, max = 25, num1 = min + (rand() % (max - min + 1));

min = 1, max = 12, num2 = min + (rand() % (max - min + 1));

while (num2 >= num1) { num2 = min + (rand() % (max - min + 1)); }

result = num1 / num2;

cout << "Division: you have 3 attempts "; cout << setw(5) << num1 << endl << "/ " << num2 << endl << "______ "; cin >> answer;

while (answer != result && attempts > 0) { cout << "That is not correct. "; cout << attempts << " attempts remaining. "; cout << setw(5) << num1 << endl << "/ " << num2 << endl << "______ "; cin >> answer; attempts--; }

if (answer == result) cout << "That is the correct answer. "; else cout << "That is incorrect. The correct answer is " << result << endl; }

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!