The problem is that some times the largest or smallest number is displayed twice. Whats the problem and how do I fix it? Im guessing its a simple logic error?

07-15-2004

Sebastiani

>> if (a > b && c)

that's not how the logical AND operator works. suppose you meant:

if (a > b && a > c)

07-15-2004

RealityFusion

Ok, I get it. Thanks!

07-15-2004

Strider

The program would flow better if the comparison logic was separated into individual functions. As it is, you just need to specify the second case in the conditional statement. Stating "&& c" for example will always be true unless c is equal to 0.

Code:

if (a > b && a > c)
cout <<"The largest number is "<<a <<endl;
if (a < b && a < c)
cout <<"The smallest number is "<<a <<endl;
if (b > a && b > c)
cout <<"The largest number is "<<b <<endl;
if (b < a && b < c)
cout <<" is The smallest number is "<<b <<endl;
if (c > b && c > a)
cout <<"The largest number is "<<c <<endl;
if (c < b && c < a)
cout <<" is The smallest number is "<<c <<endl;
if (a == b && a == c)
cout <<"All numbers are equal to each other" <<endl;