Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero)
Important notes: It has to be in C++ program
#include<iostream>
using namespace std;
double addition(double x, double y)
{
return x + y;
}
double subtraction(double x, double y)
{
return x - y;
}
double multiplication(double x, double y)
{
return x * y;
}
double division(double x, double y)
{
// division by 0 is not defined
if( y == 0.0 )
return 0.0;
return x / y;
}
int main()
{
double x, y, ans;
// infinite loop
while(1)
{
cout<<"Enter 2 numbers : ";
// get user input
cin>>x>>y;
cout<<"\nSelect an option ...\n";
cout<<"1. Addition\n";
cout<<"2. Subtraction\n";
cout<<"3. Multiplication\n";
cout<<"4. Division\n";
cout<<"5. exit\n";
int ch;
// get user input
cin>>ch;
// addition
if( ch == 1 )
{
double ans = addition(x, y);
cout<<x<<" + "<<y<<" : "<<ans<<endl;
}
// subtraction
else if( ch == 2 )
{
double ans = subtraction(x, y);
cout<<x<<" - "<<y<<" : "<<ans<<endl;
}
// multiplication
else if( ch == 3 )
{
double ans = multiplication(x, y);
cout<<x<<" * "<<y<<" : "<<ans<<endl;
}
// division
else if( ch == 4 )
{
double ans = division(x, y);
cout<<x<<" / "<<y<<" : "<<ans<<endl;
}
else
break;
cout<<endl;
}
return 0;
}
Sample Output
Write a C++ Program that simulates a basic calculator using functions which performs the operations of...
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...
Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...
Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...
Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with 2 integer type numbers a) Ask user what type of operation to perform (+, , * or/) a. If the user inputs 'none' then the program terminates. Otherwise it will keep continuing the calculation. (hint: use while) b) Ask user to provide 2 integer number inputs c) Perform operation (whatever operation they mentioned in a) d) Print result e) In division operation, perform a...
in python and use while loop Exercise: Complete the program that performs basic arithmetic operations of two input numbers. The program displays a menu for user to select a desired operation. ===== MAIN MENU ===== 1. Addition 2. Subtraction 3. Exit Select an operation (1-3): 1 Enter two numbers: 12 20 12 + 20 - 32 - MAIN MENU 1. Addition 2. Subtraction 3. Exit Select an operation (1-3): 2 Enter two numbers: 12 20 12 - 10 = 2...
PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...
This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...
Question 20: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210