Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Math Game -Ask user to practice addition, subtraction, multiplication, or di

ID: 3835646 • Letter: C

Question

C++ Math Game

-Ask user to practice addition, subtraction, multiplication, or division

-Once a skill is selected, user is asked for a range of numbers they wish to practice, inclusive to those numbers

-Numbers must be positive integers

-subtraction problems must result in positive answers

-Division problems must result in answers with a zero remainder

-User gets 1 point for correct answer (screen turns green), -1 for incorrect (screen turns red)

-incorrect answer displays the correct answer on screen

-The number of points should be displayed on the screen at all times.

The user should get one point for every correct answer and get one point deducted for every incorrect answer. The screen should turn green for every correct answer and should turn red for every incorrect answer. For any incorrect answer the program shall display the problem with the correct answer before moving to then problem. The number of points should be displayed on the screen at all times.

The three high scores (calculated by taking the number of correct answers divided by the elapsed time, correct problems per second) for each type of math operation should be stored in an external file. When someone creates a new high score and has chosen to exit the program, the program should ask the user for a user name. Then the high scores and user names must be displayed for 5 seconds before exiting the program. If the user hasn't beat one of the three high scores, the existing high scores and user names should be displayed for 5 seconds before exiting the program.

There shall be no calculations or information asked for from the main function.

Explanation / Answer

ANSWER::

#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
int choice;
int v1;
int v2;
int ans;
int total;
srand(time(0));
v1 = rand() % 100;
v2 = rand() % 100 + 1;
do
{
cout << "1: Add" << endl;
cout << "2: Subtract" << endl;
cout << "3: Multiply" << endl;
cout << "4: Divide" << endl;
cout << "0: Exit" << endl;
cout << "-- enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
cout <<"What is"<< v1 <<"+" << v2 <<"?";
cin >>ans;
total=v1+v2;
if (ans == v1 + v2)
{
cout << "Correct answer" << endl;
}
else
{
cout << "Wrong answer, please try again" << endl;
}
return 1;
case 2:
cout <<"What is"<< v1 <<"-" << v2 <<"?";
cin >>ans;
total=v1-v2;
if (ans == v1 - v2)
{
cout << "Correct answer" << endl;
}
else {
cout << "Wrong answer, please try again" << endl;
}
return 1;
case 3:
cout <<"What is"<< v1 <<"*" << v2 <<"?";
cin >>ans;
total=v1*v2;
if (ans == v1 * v2)
{
cout << "Correct answer" << endl;
}
else {
cout << "Wrong answer, please try again" << endl;
}
return 1;
case 4:
cout <<"What is"<< v1 <<"/" << v2 <<"?";
cin >>ans;
total=v1/v2;
if (ans == v1 / v2)
{
cout << "Correct answer" << endl;
}
else {
cout << "Wrong answer, please try again" << endl;
}
return 1;
default:
cout << "you chose to exit" << endl;
}
} while (choice !=0);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote