Question
#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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started