Thursday, October 13, 2016

Arithmetic Operations Using Try Catch Statement :)

Tags

Program To Display Arithmetic Operations On Two Numbers Using Try Catch :

#include<iostream>
using namespace std;
void operations()
{   int a,b;
    char c;
cout<<"Enter Two Values\n";
cin>>a>>b;
cout<<"Enter Any Arithmentic Operator";
cin>>c;
try
{
         if(c!='+'&&c!='*'&&c!='/'&&c!='-')
{
throw a;
}
else
{
switch(c)
{
case '+': cout<<"Sum is "<<a+b; break;
case '-': cout<<"Difference is "<<a-b; break;
case '*': cout<<"Product is "<<a*b; break;
case '/': cout<<"Quotient is "<<a/b; break;
}
}
}
catch(int)
{
cout<<"Invalid Operator";
}
}
main()
{
operations();
}

Output: