****C++*** You will create a math game to help people hone their math skills. Wh
ID: 3835444 • Letter: #
Question
****C++***
You will create a math game to help people hone their math skills. When the game is executed, it will ask the user if they want to practice their addition, subtraction, multiplication or division skills. Once a skill is selected, the user is asked for a range of numbers they wish to practice. As an example, I can input a "-" to practice subtraction. I then can input the numbers 10 and 20 to practice subtraction using numbers between 10 and 20 inclusive of 10 and 20.
All numbers must be positive integers. All subtraction problems must result in positive answers and all division problems must result in answers with a zero remainder.
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
#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)); // initialize random seed to current time
v1 = rand() % 100; // v1 in the range 0 to 99
v2 = rand() % 100 + 1; // v2 in the range 1 to 100
do
{
cout << "-- Menu --" << endl;
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;
// code for handling the entered choice...
//switch statements
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.