Question: Requirements: Create a C + + program that provides a menu for the user to select an operation ( addition , subtraction, multiplication, division )

Requirements:
Create a C++program that provides a menu for the user to select an operation (addition, subtraction, multiplication, division) or exit the program.
Ensure that division by zero is handled gracefully by displaying an error message and allowing the user to enter new values.
Use a loop to allow the user to perform multiple calculations until they choose to exit
Display the result of each calculation to the user.
Implement methods for each of the four arithmetic operations (addition, subtraction, multiplication, division). Each function should take two numbers as input and return the result.
Example Output:
Welcome to the Simple Calculator!
Menu:
Addition
Subtraction
Multiplication
Division
Exit
Please enter your choice: 1
Enter the first number: 5
Enter the second number: 3
Result: 5+3=8
Please enter your choice: 3
Enter the first number: 7
Enter the second number: 4
Result: 7*4=28
Please enter your choice: 4
Enter the first number: 6
Enter the second number: 0
Error: Division by zero. Please enter new values.
Please enter your choice: 2
Enter the first number: 10
Enter the second number: 2
Result: 10-2=8
Please enter your choice: 5
Hints:
Use a statement or statements to handle the menu selection.
Create separate methods for each arithmetic operation to keep your code organized and maintainable.
Use a loop to repeatedly display the menu and perform calculations until the user chooses to exit.In this project, you will create a basic calculator application that can perform four arithmetic operations: addition, subtraction, multiplication, and division. You will use methods to encapsulate the functionality of each operation.
My code so far:
#include
using namespace std;
int x;
int y;
int addition =(x + y);
int subtraction =(x - y);
int multiplication =(x * y);
int division =(x / y);
int main()
{
double a;
double b;
double c;
double d;
int e;
a = addition;
b = subtraction;
c = multiplication;
d = division;
e =0;
int choice;
choice = a || b || c|| d || e;
cout "Welcome to the Simple Calculator!" endl;
cout "Menu:" endl;
cout "A. Addition" endl;
cout "B. Subtraction" endl;
cout "C. Multiplication" endl;
cout "D. Division" endl;
cout "E. Exit" endl;
cout "Please select option A, B, C, D, or E to exit: ";
cin >> choice;
while ((choice != e)){
if ((choice = a)){
cout "Enter x: ";
cin >> x;
cout "Enter y: ";
cin >> y;
cout "The sum is: " a endl;
}
else if ((choice = b)){
cout "Enter x: ";
cin >> x;
cout "Enter y: ";
cin >> y;
cout "The difference is: " b endl;
}
else if ((choice = c)){
cout "Enter x: ";
cin >> x;
cout "Enter y: ";
cin >> y;
cout "The product is: " c endl;
}
else if ((choice = d)){
cout "Enter x: ";
cin >> x;
cout "Enter y: ";
cin >> y;
cout "The quotient is: " d endl;
}
else if (d !=0){
cout "Please try again." endl;
cout "Enter x: ";
cin >> x;
cout "Enter y: ";
cin >> y;
cout "The quotient is: " d endl;
}
else {
break;
}
}
return 0;
}
 Requirements: Create a C++program that provides a menu for the user

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!