50. Divide by Zero Handling

Write a function divide that divides two integers:

  • int divide(int a, int b)

If b == 0, it should throw a std::runtime_error with the message:  Division by zero

  • Otherwise, return the result of a / b.
     

The program already reads two integers, calls divide, and uses try/catch to handle the exception.
 You only need to implement the divide function.


Example
 Input:

10 2

Output:

Result: 5

Here 10/2 = 5

 

Input:

7 0

Output:

Error: Division by zero

Here 7/0 = Not Divisible by 0 condition.

Loading...

Input

10 2

Expected Output

Result: 5