C++ Program To Perform all Arithmetic Calculation using switch case

This program takes an arithmetic operator (+, -, *, /) and two operands from a user and performs the operation on those two operands depending upon the operator entered by user.

C++ Program To Perform all Arithmetic Calculation using switch case

#include<iostream>
using namespace std;
int main() {
    int x, y, res;
    int ch;

    cout << "Enter 1 For Addition :";
    cout << "\nEnter 2 For Subtraction :";
    cout << "\nEnter 3 For Multiplication :";
    cout << "\nEnter 4 For Division :";
    cout << "\nEnter 5 For Modulus :";
    cin >> ch;

    switch (ch) {
        case 1:
        {
            cout << "\nEnter Two Numbers :";
            cin >> x >> y;

            res = x + y;

            cout << "\nResult is :" << res;
            break;
        }
        case 2:
        {
            cout << "\nEnter Two Numbers :";
            cin >> x >> y;

            res = x - y;

            cout << "\nResult is :" << res;
            break;
        }
        case 3:
        {
            cout << "\nEnter Two Numbers :";
            cin >> x >> y;

            res = x * y;

            cout << "\nResult is :" << res;
            break;
        }
        case 4:
        {
            cout << "\nEnter Two Numbers :";
            cin >> x >> y;

            res = x / y;

            cout << "\nResult is :" << res;
            break;
        }
        case 5:
        {
            cout << "\nEnter Two Numbers :";
            cin >> x >> y;

            res = x % y;

            cout << "\nResult is :" << res;
            break;
        }
    }

    return 0;
}

Output of Program

Enter 1 For Addition :
Enter 2 For Subtraction :
Enter 3 For Multiplication :
Enter 4 For Division :
Enter 5 For Modulus :1

Enter Two Numbers :8
9

Result is :17