C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using Switch case

#include <iostream>
using namespace std;
int main() {
    char op;
    float num1, num2;
    cout << "Enter an arithemetic operator(+ - * /)\n";
    cin >> op;
    cout << "Enter two numbers \n";
    cin >> num1 >> num2;
    switch(op) {
        case '+':
                cout << num1 << " + " << num2 << " = " << num1+num2;
                break;
        case '-':
                cout << num1 << " - " << num2 << " = " << num1+num2;
                break;
        case '*':
                cout << num1 << " * " << num2 << " = " << num1*num2;
                break;
        case '/':
                cout << num1 << " / " << num2 << " = " << num1/num2;
                break;
        default:
                printf("ERROR: Invalid Operation");
    }
    return 0;
}

OUTPUT:

Enter an arithemetic operator(+ - * /)
+
Enter two numbers
3 7
3 + 7 = 10

Leave a Comment