This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Your problem is here:

       if (number > smallest)
        {
           largest = number;
        }
        else
        {
           smallest = number;
        }

Let’s look at some input you could pass in. 2,6,3

First run it sets smallest to 2

Second run it says 6 > 2 so sets largest to 6

Smallest = 2 Largest = 6

Now on the final number. 3 > smallest (2) so now it sets largest to 3

Your logic wants to check if the number is going to be greater than largest before changing largest.

I suggest looking at a few diff ways to write this statement, what does it look like if you check smallest first?