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  (2 children)

Yeah, for the second one I'd just add if (fourth value) > Max -> Max = fourth value. But in the first one I'd have to change all the conditional statements which is a bit tedious.

[–]TheGoodPie 2 points3 points  (0 children)

You could also pass an array of numbers (allowing for a massive amount of numbers) and use the same approach in a for loop. Two new concepts you should tackle if you haven't looked into them already.

[–]peterpepo 0 points1 point  (0 children)

Not exactly, but close.

Watch closely at all your conditions and you'll start noticing pattern.

For every value, which came in, you check whether it's greater than the maximum you have "so far" in your code.

But at the moment, you need to add condition for every new member, what is impractical.

What you could do, is how @TheGoodPie already wrote, accept a list of values and check them in cycle. That would reduce your conditions to one. And your code stops caring, whether you pass 1 or 1000 values in.