Searching...

Simple Calculator with Switch Statement

15:44

#include <iostream>
using namespace std;
int main()
{
double num1,num2;
char op;
cout << "Enter 1st Number, operator & 2nd Number\n";
cin >> num1 >> op >>num2;
switch (op)
{
case '+':
cout << "Ans= " << num1+num2 <<endl;
break;
case '-':
cout << "Ans= " << num1-num2 <<endl;
break;
case '*':
cout << "Ans= "<<num1*num2<<endl;
break;
case '/':
cout << "Ans= "<<num1/num2<<endl;
break;
default:
cout << "Invalid Operator....!!!!!!"<<endl;
}
return 0;
}

0 comments:

Post a Comment

Thanks For Your FeedBack....