Home » Blog » Make Simple Calculator Using Switch Case

Make Simple Calculator Using Switch Case

# include <iostream>
using namespace std;

int main()
{
    char operation;
    float no1, no2;
	
    cout << "Enter operationerator either + or - or * or /: ";
    cin >> operation;
	
    cout << "Enter two operationerands: ";
    cin >> no1 >> no2;
	
    switch(operation)
    {
        case '+':
            cout << no1+no2;
            break;
        case '-':
            cout << no1-no2;
            break;
        case '*':
            cout << no1*no2;
            break;
        case '/':
            cout << no1/no2;
            break;
        default:
            cout << "Error! operation is not correct";
            break;
    }
	
    return 0;
}

OutPut

Enter operator either + or - or * or divide : +
Enter two operands: 
3.4
8.4
3.4 - 8.4 = 11.8

 

Leave a Reply

Your email address will not be published.