*Must be coded to this format* You will create a math game to help people hone t
ID: 3825509 • Letter: #
Question
*Must be coded to this format*
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.
(Programmed in C++)
Explanation / Answer
Please review
#include <iostream>
using namespace std;
int main() {
while(1){
int number1=0,number2=0,total=0;
float totaldiv=0.0;
char opr=' ';
cout<<"please select operation to be performed."<<endl;
cout<<"1:Press '+' for addition"<<endl;
cout<<"2:Press '-' for subtraction"<<endl;
cout<<"3:Press '*' for multiplication"<<endl;
cout<<"4:Press '/' for divide"<<endl;
cin>>opr;
switch(opr)
{
case '+':
cout<<"You have selected addition '+'"<<endl;
cout<<"Please enter positive value for number1"<<endl;
cin>>number1;
cout<<"Please enter number2"<<endl;
cin>>number2;
if(number1<0)
{
cout<<"You have enter negative value please try again";
break;
}
else if(number2<0)
{
cout<<"You have enter negative value please try again";
break;
}
else
{
total=number1+number2;
cout<<"The addition of number is :";
cout<<total;
}
break;
case '-':
cout<<"You have selected subtraction '-'"<<endl;
cout<<"Please enter positive value for number1"<<endl;
cin>>number1;
cout<<"Please enter number2"<<endl;
cin>>number2;
if(number1<0)
{
cout<<"You have enter negative value please try again";
break;
}
else if(number2<0)
{
cout<<"You have enter negative value please try again";
break;
}
else
{
total=number1-number2;
cout<<"The subtraction of number is :";
cout<<total;
}
break;
case '*':
cout<<"You have selected Multiplication '*'"<<endl;
cout<<"Please enter positive value for number1"<<endl;
cin>>number1;
cout<<"Please enter number2"<<endl;
cin>>number2;
if(number1<0)
{
cout<<"You have enter negative value please try again";
break;
}
else if(number2<0)
{
cout<<"You have enter negative value please try again";
break;
}
else
{
total=number1*number2;
cout<<"The multiplication of number is :"<<endl;
cout<<total;
}
break;
case '/':
cout<<"You have selected division '/'"<<endl;
cout<<"Please enter positive value for number1"<<endl;
cin>>number1;
cout<<"Please enter number2"<<endl;
cin>>number2;
if(number1<0)
{
cout<<"You have enter negative value please try again";
break;
}
else if(number2<0)
{
cout<<"You have enter negative value please try again";
break;
}
else
{
if(total%2==0){
cout<<"The division of number is :0";
}
else
{
total=number1/number2;
cout<<"The division of number is :"<<endl;
cout<<total;
}
}
break;
}
return 0;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.