Question: Requirements: Create a C + + program that provides a menu for the user to select an operation ( addition , subtraction, multiplication, division )
Requirements:
Create a Cprogram 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:
Enter the first number:
Enter the second number:
Result:
Please enter your choice:
Enter the first number:
Enter the second number:
Result:
Please enter your choice:
Enter the first number:
Enter the second number:
Error: Division by zero. Please enter new values.
Please enter your choice:
Enter the first number:
Enter the second number:
Result:
Please enter your choice:
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 ;
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
cout "Please try again." endl;
cout "Enter x: ;
cin x;
cout "Enter y: ;
cin y;
cout "The quotient is: d endl;
else
break;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
