Design a program to read three integer numbers x, y and z and Evaluate arithmetic division for R, given R = z / (x - y). Use exception handling to throw an exception in case division by zero is attempted
#include <iostream>
using namespace std;
int main()
{
int x,y,z,R;
cout<<"Enter the value of x: ";
cin>>x;
cout<<"Enter the value of y: ";
cin>>y;
cout<<"Enter the value of z: ";
cin>>z;
if ((x-y)==0){
throw runtime_error("Math error: Attempted to divide by Zero\n");
}
else{
R=z/(x-y);
cout<<"R is "<<R<<endl;
}
return 0;
}
Comments
Leave a comment