Finding the largest of 3 numbers

jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
edited November -1 in Working with GS (Mac)
Anyone know of a simple way of comparing 3 numbers and finding the largest? I have a sound playing when displaying the score, but i only want it to display while it counts up to the largest number.

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    i actually just found this on yahoo answers, im posting it incase anyone else is looking for similar
    Create a variable smallest and one for largest.

    Next assign the first number to both.

    Then compare the second number to smallest, if it is smaller, replace smallest with the second. if not, do nothing. compare the second number to largest, if it is larger, replace largest with the second number. (you can code this more elegantly by knowing if it is smaller, it wont be larger - but don't worry about that until you've got it working first)

    repeat this process with the third number comparing to smallest and largest respectively.

    hope that helps and solves your issue.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    max(game.Num1,max(game.Num2,game.Num3))
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    that is a lot easier :) thanks codemonkey!
Sign In or Register to comment.