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

Using Visual Studio C++ Write a program that takes two operands followed by an o

ID: 3562142 • Letter: U

Question

Using Visual Studio C++
Write a program that takes two operands followed by an operator and
outputs the resull. For exa.mple:
100 3.14 +
4 5 *
4 5 div
(This is called "reverse Polish notation)

Read the operation into a string called operation and usc an if-statement
to figure out which operation the user wants, for example, if (operation=="+")
. Read the operands into variables of type double. Implement
this for operations called +, - , ., I, plus , minus, Illul, and div with their
obvious meanings.

Explanation / Answer


#include "stdafx.h"
#include <iostream>
#include<string.h>
using namespace std;

int main()
{

   char oper;
   float x ,y;
   std::cin>>x>>y;
   oper=getchar();
   switch(oper)
        {
            case '+': result=a+b;
                std::cout<<" Addition: "<<result;
                break;
            case '-': result=a-b;
                std::cout<<" Subtraction: "<<result;
                break;
            case '*': result=a*b;
                std::cout<<" Multiplication: "<<result;
                break;
            case '/': result=a/b;
                std::cout<<" Division: "<<result;
                break;
            case '%': result=a%b;
                std::cout<<" Remainder: "<<result;
                break;
            case 6: exit(1);
            default: std::cout<<" Enter a valid choice!";
        }
        return 0;
  
}

sample output:

5 6 +

Addition 11

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