inc++,Write a menu driven application for a game that your pupils can use to imp
ID: 3904506 • Letter: I
Question
inc++,Write a menu driven application for a game that your pupils can use to improve their arithmetic skills. Once started, the game should allow the player to choose one option from the four presented options namely: 1. Perform a Modulus division of two numbers 2. Perform Multiplication of two numbers 3. Perform Subtraction of two numbers 4. Exit Upon selection of the operation they wish to undertake, the program should then allow the user to provide the required numbers for the operation. Once values are provided, the program should ask the user what the response is when the desired operation is carried out on the two number. A user should be given two chances only to try and guess the right response, if they exhaust the two chances they should be provided with the right answer. If they guess the result correctly, they should be recommended with a message of congratulation. After this is done, the user should be presented with the menu requesting them to choose another operation to carry out or exit the program.inc++language
Explanation / Answer
ScreenShot
Program
/*This program is a small game to predict arithmetic values
Here user got the 3 arithmetic calculation option
They got two chances to predict the result*/
//Header file for I/O
#include<iostream>
using namespace std;
//Function prototypes
void menu();
int modDivision();
int mult();
int sub();
bool userResponse(int val);
//Main method
int main()
{
//Variables for user choice and result
int ch,ans=0;
//Menu display
menu();
//Prompt user for their choice of operation
cout << "Please enter the operation you want to perform:";
cin >> ch;
//Loop for checking operations
while (ch > 0 && ch <= 4) {
//Perform each operations according to the user choice
switch (ch) {
//Modulo division
case 1:
ans=modDivision();
if (userResponse(ans) != true) {
cout<<"your responses are wrong!!!"<<endl;
cout << "Answer is=" << ans<<endl;
}
break;
//Multiplication
case 2:
ans = mult();
if (userResponse(ans) != true) {
cout << "your responses are wrong!!!" << endl;
cout << "Answer is=" << ans<<endl;
}
break;
//Subtraction
case 3:
ans = sub();
if (userResponse(ans) != true) {
cout << "your responses are wrong!!!" << endl;
cout << "Answer is=" << ans<<endl;
}
break;
//Otherwise exit
case 4:
cout << " Good Bye!!!" << endl;
exit(0);
}
//Repeat until user opt for exit
menu();
cout << "Please enter the operation you want to perform:";
cin >> ch;
}
cout << "Your choice is wrong , Please restart the game enter choice within 1-4!!!"<<endl;
return 0;
}
//Menu function definition
void menu() {
cout << " Your Options" << endl;
cout << "1. Perform a Modulus division of two numbers 2. Perform Multiplication of two numbers 3. Perform Subtraction of two numbers 4. Exit" << endl;
}
//Modulo division calculation , return remainder
int modDivision() {
int num1, num2;
cout << "Please enter two numbers for performing modulus division:";
cin >> num1>>num2;
return num1 % num2;
}
//Multiplication and return answer
int mult() {
int num1, num2;
cout << "Please enter two numbers for performing multiplication:";
cin >> num1 >> num2;
return num1 * num2;
}
//Do subtraction and return answer
int sub() {
int num1, num2;
cout << "Please enter two numbers for performing Subtraction:";
cin >> num1 >> num2;
return num1 - num2;
}
//Check user response and if they got correct return true otherwise false
bool userResponse(int val) {
int res,i=0;
while(i<2) {
cout << "Please enter your response:";
cin >> res;
if (res == val) {
cout << "You are Awesome!!!" << endl;
return true;
}
else {
i = i + 1;
}
}
return false;
}
------------------------------------------------------
Output
Your Options
1. Perform a Modulus division of two numbers
2. Perform Multiplication of two numbers
3. Perform Subtraction of two numbers
4. Exit
Please enter the operation you want to perform:1
Please enter two numbers for performing modulus division:4
5
Please enter your response:1
Please enter your response:4
You are Awesome!!!
Your Options
1. Perform a Modulus division of two numbers
2. Perform Multiplication of two numbers
3. Perform Subtraction of two numbers
4. Exit
Please enter the operation you want to perform:2
Please enter two numbers for performing multiplication:10
35
Please enter your response:100
Please enter your response:510
your responses are wrong!!!
Answer is=350
Your Options
1. Perform a Modulus division of two numbers
2. Perform Multiplication of two numbers
3. Perform Subtraction of two numbers
4. Exit
Please enter the operation you want to perform:3
Please enter two numbers for performing Subtraction:4 9
Please enter your response:5
Please enter your response:4
your responses are wrong!!!
Answer is=-5
Your Options
1. Perform a Modulus division of two numbers
2. Perform Multiplication of two numbers
3. Perform Subtraction of two numbers
4. Exit
Please enter the operation you want to perform:4
Good Bye!!!
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.