Need help comparing 3 numbers...

admin

Administrator
Staff member
Depending on the order that I enter the 3 numbers to be compared I get either the smallest is undefined or the largest is undefined.

// compare to find the smallest of the 3 numbers
if (no1Value <= no2Value)
if (no1Value <= no3Value)
smallest = no1Value;
else
if (no2Value <= no3Value)
smallest = no2Value;
else
smallest = no3Value;

// compare to find the largest of the 3 numbers
if (no1Value >= no2Value)
if (no1Value >= no3Value)
largest = no1Value;
else
if (no2Value >= no3Value)
largest = no2Value;
else
largest = no3Value;

Any help would be appreciated.

Thank you :)
 
Back
Top