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

Topics Methods Description Write a program that will implement a simple calculat

ID: 3567517 • Letter: T

Question

Topics Methods Description Write a program that will implement a simple calculator. The program will prompt the user to input an operation and two decimal numbers. It will perform the specified operation on the two decimal numbers and will display the result. The program will allow the following values for operation: + (means add) - (means subtract) * (means multiply) / (means divide) The program will do the above repeatedly so that a user may perform different operations on a different pair of numbers. /* Java users The program will end when the user presses Cancel in response to the prompt for entering the operation. */ /* C++ users The program will end when the user enters x for operation. Testing Test Run Enter an operation + Enter the first number 2.2 Enter the second number 1.1

Explanation / Answer

===========================

Program

===========================

#include <iostream>
int main()
{
   double num1,num2,result;
   char option;
   cout<<"Enter an operation (+,-,/,*) ";
   cin>>option;
   cout<<"Enter the first number ";
   cin>>num1;
   cout<<"Enter the second number ";
   cin>>num2;
  
   switch(option)
{
        case '+' :
  
    result = num1+num2;  
       break;
        case '-' :
  
    result = num1-num2;  
       break;
        case '*' :
  
    result = num1*num2;  
       break;
        case '/' :
  
    result = num1/num2;  
       break;
      
        default :
cout<<"Invalid operator ";
}
cout<<"Result:"<<result<<endl;

return 0;
}

===================================