Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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 Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

How do rapid growth firms deal with potential cash flow shortfalls?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago