Calculator using Switch Case in C++


Example Program:

Here is the simple calculator program using Switch Case in C++.

Source Code

#include<iostream>
using namespace std;
int main()
{
    char oper;
    float n1, n2;
    cout<<"\nEnter an operator (+,-,*,/): ";
    cin>>oper;
    cout<<"\nEnter two numbers: "<<endl;
    cin>>n1>>n2;
    switch(oper)
    {
        case '+':
            cout<<n1<<" + "<<n2<<" = "<<n1+n2;
            break;
        case '-':
            cout<<n1<<" - "<<n2<<" = "<<n1-n2;
            break;
        case '*':
            cout<<n1<<" * "<<n2<<" = "<<n1*n2;
            break;
        case '/':
            cout<<n1<<" / "<<n2<<" = "<<n1/n2;
            break;
        default:
            cout<<"Error! The operator is not correct";
            break;
    }
    return 0;
}
To download raw file Click Here

Output

Enter an operator (+,-,*,/): *
Enter two numbers: 
23
21
23 * 21 = 483

Basic Programs


Flow Control

IF Statement Examples


Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes