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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.