Thursday, October 13, 2016

Arithmetic Operations Using Multiple Catch Statements:)

Tags

Program To Display Arithmetic Operations On Two Numbers Using Multiple Catch Statements:
#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 '/':

if(b==0)
{
throw float(a);
}
else
{
cout<<"Quotient is "<<a/b; break;
}
             
}
}}
catch(float)
               {
                cout<<"Divide By Zero";
  }
catch(int)
{
cout<<"Invalid Operator";
}
}
main()
{
operations();
}
Output: