Answer to Question #188225 in C++ for Asma M.Hussain

Question #188225

Write a program that mimics a calculator . The program should take as input two integers and the operation to be performed . It should then output the numbers , the operator and the result . (For division , if the denominator is zero , output an appropriate message.) .Some sample output as follow 

3 + 4 = 7 


13 * 5 = 65


1
Expert's answer
2021-05-02T11:07:02-0400
#include <iostream>

using namespace std;

int main()
{
     int operand1, operand2;
     char operator;
     cout << "Enter the first operand: ";
     cin >> operand1;
     cout << "Enter the second operand: ";
     cin >> operand2;
     cout << "Enter the operator(+, -, *, /): ";
     cin >> operator;
     if(operator == '+')
     {
           cout << opreand1 << " + " << operand2 << " = " << operand1 + operator2 << endl;
      }
     else if(operator == '-')
     {
           cout << opreand1 << " - " << operand2 << " = " << operand1 - operator2 << endl;
      }
     else if(operator == '*')
     {
           cout << opreand1 << " * " << operand2 << " = " << operand1 * operator2 << endl;
      }
      else if(operator == '/')
     {
           if(operand2)
           {
                 cout << opreand1 << " / " << operand2 << " = " << (float)operand1 / (float)operator2 << endl;
           }
           else
                  cout << "Warning! Dividing by zero" << endl;
      }
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS