Header Ads

Header ADS

SIMPLE CALCULATOR USING SWITCH IN C++

#include <iostream>
using namespace std;

int main ()
{

    char ch;
    float num1, num2;

    cout<<"PLEASE ENTER 1ST OPERAND : ";
    cin>>num1;

    cout<<"PLEASE SELECT OPERATOR : + , - , * OR / , PLEASE SELECT ONE : ";
    cin>>ch;

    cout<<"PLEASE ENTER 2ND OPERAND : ";
    cin>>num2;

    switch (ch)
    {

    case '+':
        cout<<"THE ADDING RESULT IS : ";
        cout<<num1 + num2<<endl;
        break;

    case '-':
        cout<<"THE SUBTRACTION RESULT IS : ";
        cout<<num1 - num2<<endl;
        break;

    case '*':
        cout<<"THE MULTIPLICATION RESULT IS : ";
        cout<<num1 * num2<<endl;
        break;

    case '/':
        cout<<"THE DIVIDING RESULT IS : ";
        cout<<num1 / num2<<endl;
        break;

    default:

        cout<<"THE RESULT IS ERROR !!!"<<endl;

    }


    return 0;
}
OUTPUT







No comments

Powered by Blogger.