Question
c++ why is it not dividng correctly? Everything except the division is working correctly. The divide by 0 exception works, but the division doesn't work
c++ why is it not dividng correctly?
Everything except the division is working correctly. The divide by 0 exception works, but the division doesn't work if the first number is smaller than the second number. Here is my code.
Thanks.
#include
using namespace std;
//Template for Maximum
template
T Maximum(T arg1, T arg2)
{
if(arg1 > arg2)
return arg1;
else
return arg2;
}
//Template for Minimum
template
T Minimum(T arg1, T arg2)
{
if(arg1 > arg2)
return arg2;
else
return arg1;
}
//Template for Division
template
T Divide(T arg1, T arg2)
{
if(arg2 == 0){
throw "You cannot device by zero! ";
}
return (arg1 / arg2);
}
int main()
{
//Declare variables
int num1, num2;
int big, little, division;
//Ask for the numbers and store them
cout << "Please enter the first number : ";
cin >> num1;
cout << "Please enter the second number : ";
cin >> num2;
big = Maximum(num1, num2);
little = Minimum(num1, num2);
//catch exception for dividing by zero
try
{
division = Divide(num1, num2);
}
catch(const char* msg)
{
cerr << msg < } //Display the Maximum, Minimum, and quotient cout << "Largest of two is : " << big << endl; cout << "Smallest of the two is : " << little << endl; cout << "The division of the two numbers is : " << division << endl; return 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