Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; // Function prototype double divide(int, int); int main() { int num1, num2; // To hold two numbers double quotient; // To

#include using namespace std;

// Function prototype double divide(int, int);

int main() { int num1, num2; // To hold two numbers double quotient; // To hold the quotient of the numbers

// Get two numbers. cout << "Enter two numbers: "; cin >> num1 >> num2;

// Divide num1 by num2 and catch any // potential exceptions. try { quotient = divide(num1, num2); cout << "The quotient is " << quotient << endl; } catch (char *exceptionString) { cout << exceptionString; }

cout << "End of the program. "; return 0; }

//******************************************** // The divide function divides numerator by * // denominator. If denominator is zero, the * // function throws an exception. * //********************************************

double divide(int numerator, int denominator) { if (denominator == 0) throw "ERROR: Cannot divide by zero. ";

return static_cast(numerator) / denominator; }

C++

What problem is it when denominator equals 0?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions