To post code:
[co
de]your code here[/co
de]
As for your problem.. here is what your code is doing:
|
if (number1 < number2 < number3)
|
The < operator checks the values to the left of it and the right of it. if the left one is less than the right one, it returns 1 (true), otherwise it returns 0 (false).
So let's plug in numbers to make this easier to follow. Let's say:
number1 = 15
number2 = 6
number3 = 10
The computer will do this:
1 2 3
|
if( 15 < 6 < 10 )
if( (15<6) < 10 ) // is 15 < 6? no, so replace with 0:
if( 0 < 10 ) // is 0 less than 10? yes so this if statement succeeded
|
As you might be able to see, the compiler isn't doing at all what you might expect. It's comparing the output of one < operator with a number. It isn't comparing all 3 numbers to each other.
Furthermore, you do this line:
|
cout << "smallest is " << number1 << number2 << number3 << endl;
|
Here, you're not printing the smallest number, you're just printing all 3 numbers one after the other.
To find the smallest, you'll need to use another variable, let's call it 'smallest'. Check 'smallest' against each number. If a number is smaller than smallest, then replace smallest with that number. Once you've checked it against all 3 numbers, you'll know you have the smallest of the 3.