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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!