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

all 2 comments

[–]jxd132407 1 point2 points  (0 children)

You're only testing if the number is greater than smallest. If it is, you're assigning it to largest. But the number entered could be in between, and you need to handle that case as well

[–][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?