Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 3 Program a Calculator 8 points Write a program that can be used as a ca

ID: 3907791 • Letter: P

Question

Problem 3 Program a Calculator 8 points Write a program that can be used as a calculator. Prompt the user to enter which operation he/she would like to perform, that is addition, subtraction, multiplication, or division. Use a switch statement to properly handle the operator entered by the user. Then prompt the user to enter two operands. An example of the program may look like this: Calculator What operation would you like to perform? Addition),Subtraction),Multiplication *),or Division (/) Enter an operator: + Enter operand 1: 23 Enter operand 2: 45 The results is: 23 + 45 = 78

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
   char ch;
   int a,b;
   cout<<"Calculator ";
   cout<<"-------------------- ";
   cout<<"Which operation do you want to perform?(+,*,-,/): ";
   cin>>ch;
   switch(ch)
   {
      
       case '+':
           cout<<"Enter the operand 1 ";
           cin>>a;
           cout<<"Enter the operand 2 ";
           cin>>b;
           cout<<"The result is:"<<a<<ch<<b<<"="<<a+b;
           break;
          
       case '-':
           cout<<"Enter the operand 1 ";
           cin>>a;
           cout<<"Enter the operand 2 ";
           cin>>b;
           cout<<"The result is:"<<a<<ch<<b<<"="<<a-b;
           break;
      
       case '*':
           cout<<"Enter the operand 1 ";
           cin>>a;
           cout<<"Enter the operand 2 ";
           cin>>b;
           cout<<"The result is:"<<a<<ch<<b<<"="<<a*b;
           break;
      
       case '/':
           cout<<"Enter the operand 1 ";
           cin>>a;
           cout<<"Enter the operand 2 ";
           cin>>b;
           cout<<"The result is:"<<a<<ch<<b<<"="<<a/b;
           break;
          
       default:
           cout<<"Invalid input ";
          
          
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote