YOU NEED TO DESIGN A CALCULATOR THAT Perform four bssic arithmetic operations.it then displays list of arithmetic operatios.the uset select one operation&the program displays the result of corresponding opperation.
Answers
// C++ program to make a simple calculator to Add, Subtract,
// Multiply or Divide using switch...case statement
#include <iostream>
using namespace std;
int main() {
char op;
float num1, num2;
cout << "Enter an arithemetic operator(+ - * /)\n";
cin >> op;
cout << "Enter two numbers as operands\n";
cin >> num1 >> num2;
switch(op) {
case '+':
cout << num1 << " + " << num2 << " = " << num1+num2;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1+num2;
break;
case '*':
cout << num1 << " * " << num2 << " = " << num1*num2;
break;
case '/':
cout << num1 << " / " << num2 << " = " << num1/num2;
break;
default:
printf("ERROR: Unsupported Operation");
}
return 0;
}
Output
Enter an arithemetic operator(+ - * /)
+
Enter two numbers as operands
2 8
2 + 8 = 10
Enter an arithemetic operator(+ - * /)
*
Enter two numbers as operands
3 7
3 * 7 = 21
In above program, we first take an arithmetic operator as input from user and store it in a character variable op. Our calculator program only support four basic arithmetic operators, Addition(+), Subtraction(-), Multiplication(*) and Division(/). Then we take two integers operands as input from user and store it in variable num1 and num2