Answer to Question #289980 in C++ for ali

Question #289980

. Write a program that simulates a simple calculator. It reads two integers and a character. If the character is +, then the sum of the two numbers is printed, if the character is –, then the difference of the two numbers is printed, if the character is *, then multiplication of the two numbers is printed; if the character is /, then the quotient is printed; if the character is %, then the remainder is printed.


1
Expert's answer
2022-01-26T06:57:31-0500
#include <iostream>


int main()
{
    char action = '.';
    double a = 0, b = 0;
    std::cout<<"Please enter two integers: ";
    std::cin>>a>>b;
    std::cout<<"Please enter an action to these integers (+, -, *, /, %): ";
    std::cin>>action;
    switch(action)
    {
        case '+':
            std::cout<<a+b<<std::endl;
            break;
        case '-':
            std::cout<<a-b<<std::endl;
            break;
        case'*':
            std::cout<<a*b<<std::endl;
            break;
        case '/':
            std::cout<<a/b<<std::endl;
            break;
        case '%':
            std::cout<<(int)a%(int)b<<std::endl;
            break;
    }
    
    
    
    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