C++ Program to perform arithmetic operations using switch case


In this program, You will learn how to perform arithmetic operations using switch case in C++.


Enter your choice = 1

10 + 10 = 20


Example: How to perform arithmetic operations using switch case in C++

Run it Now
#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:

Enter 1 For Addition :1
Enter 2 For Substraction :
Enter 3 For Multiplication :
Enter 4 For Division :
Enter 5 For Modulus :
Enter Two Numbers :6 3
Result is :9