1 Answers
Code:
#include <iostream>
using namespace std;
void divide(float a, float b, float c)
{
float x = a-b-c;
if(x !=0 )
{
cout<<“Result (c/x) = ” << c/x << “\n”;
}
else
{
throw(x);
}
}
int main()
{
float a, b, c, d, e, f;
try
{
cout<<“Enter the values of a, b, c, d, e, f:”;
cin>>a>>b>>c>>d>>e>>f;
divide(a, b ,c);
divide(d, e, f);
}
catch(float i)
{
cout<<“Exception caught Float : DIVIDE BY ZERO”;
cout<<“\nEND” << endl;
}
catch(int i)
{
cout<<“Exception caught Integer : DIVIDE BY ZERO”;
cout<<“\nEND” << endl;
}
catch(double i)
{
cout<<“Exception caught Double : DIVIDE BY ZERO”;
cout<<“\nEND” << endl;
}
}
Output:
Enter the values of a, b, c, d, e, f:20
10
5
20
10
10
Result (c/x) = 1
Exception caught Float : DIVIDE BY ZERO
END