**Must follow all parameters and use a \"seed\" *****Must be coded to this forma
ID: 3833519 • Letter: #
Question
**Must follow all parameters and use a "seed"
*****Must be coded to this format in 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
the code is given below :
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
void add(double n1,double n2);
void sub(double n1,double n2);
void mult(double n1,double n2);
void div(double n1,double n2);
int main(int nNumberofArgs,char* pszArgs[])
{
int n1,n2;
int choice;
cout << "Welcome to the math game" << endl;
for(;;)
{
cout << "Enter a number choice: " << endl;
cout << "1 - Addition" << endl;
cout << "2 - sub" << endl;
cout << "3 - multplication" << endl;
cout << "4 - div" << endl;
cout << "5 - Exit" << endl;
cout << endl << "Choice: ";
cin >> choice;
if(cin.fail())
{
cout << "Invalid answer, now quitting to prevent crash..." << endl;
system("PAUSE");
return 0;
}
srand((unsigned)time(0));
n1 = rand() % 100 + 1;
n2 = rand() % 100 + 1;
switch(choice)
{
case 1:
addition(n1,n2);
break;
case 2:
sub(n1,n2);
break;
case 3:
mult(n1,n2);
break;
case 4:
div(n1,n2);
break;
case 5:
cout << "Thank you for playing please come again!" << endl;
system("PAUSE");
return 0;
default:
cout << "Invalid Number!" << endl;
system("PAUSE");
return 0;
}
}
}
void addition(double n1,double n2)
{
double answer;
cout << "What is " << n1 << " + " << n2 << "?" << endl;
cout << "Answer: ";
cin >> answer;
if(answer == n1 + n2)
{
cout << endl << "Correct!" << endl << endl;
}
else
{
cout << endl << "Wrong! The right answer was " << n1 + n2 << endl << endl;
}
}
void sub(double n1,double n2)
{
double answer;
cout << "What is " << n1 << " - " << n2 << "?" << endl;
cout << "Answer: ";
cin >> answer;
if(answer == n1 - n2)
{
cout << endl << "Correct!" << endl << endl;
}
else
{
cout << endl << "Wrong! The right answer was " << n1 * n2 << endl << endl;
}
}
void mult(double n1,double n2)
{
double answer;
cout << "What is " << n1 << " * " << n2 << "?" << endl;
cout << "Answer: ";
cin >> answer;
if(answer == n1 * n2)
{
cout << endl << "Correct!" << endl << endl;
}
else
{
cout << endl << "Wrong! The right answer was " << n1 * n2 << endl << endl;
}
}
void div(double n1,double n2)
{
double answer;
double r = n1 / n2;
cout << "What is " << n1 << " / " << n2 << "?" << endl;
cout << "Remember that your answer must only have 6 numbers in it, round" << endl;
cout << "0 does not count as a number, remember to do 0.123 etc." << endl;
cout << "Answer: ";
cin >> answer;
if(answer == r)
{
cout << endl << "Correct!" << endl << endl;
}
else
{
cout << endl << "Wrong! The right answer was " << r << endl << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.