Answer to Question #188071 in C++ for Rida saeed

Question #188071

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 number ,the operator and result


1
Expert's answer
2021-05-03T01:20:03-0400
#include <iostream>
using namespace std;
int main(){
    int x, y;
    char c;
    cout<<"Input expression, eg 4 + 5\n";
    cin>>x;
    cin>>c;
    cin>>y;
    cout<<x<<" "<<c<<" "<<y<<" = ";
    switch(c){
        case '+': cout<<x + y; break;
        case '-': cout<<x - y; break;
        case '*': cout<<x * y; break;
        case '/': cout<<x / y; break;
        case '%': cout<<x % y; break;
        default: cout<<"Invalid operator!";
    }
    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