Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions