Answer to Question #193911 in C++ for ram@2002

Question #193911

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


1
Expert's answer
2021-05-15T17:16:00-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS