Friday, 16 November 2012

Simple Calculator with Switch Statement.


#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;
}

No comments:

Post a Comment