Automatic User is banned. Joined Mar 19, 2011 Posts 5,304 Reacts 0 Reputation 0 Credits 0 May 7, 2011 #1 What's the best way to find the highest value out of 5 variables? I know you can do this: Code: Int Highest = Var1; If(Highest < Var1) { Highest = Var1; } else if(Highest < Var2) { Highest = Var2; } else if(Highest < Var3) { Highest = Var3; } else if(Highest < Var4) { Highest = Var4; } else if(Highest < var5) { Highest = Var5; } Note: I know that won't work, it's just because I typed it in my browser and I'm to lazy to make a longer version (It may work, but it would most likely just scan till ONE is higher then stop, I need the find the highest But it's to messy. Any other ways?
What's the best way to find the highest value out of 5 variables? I know you can do this: Code: Int Highest = Var1; If(Highest < Var1) { Highest = Var1; } else if(Highest < Var2) { Highest = Var2; } else if(Highest < Var3) { Highest = Var3; } else if(Highest < Var4) { Highest = Var4; } else if(Highest < var5) { Highest = Var5; } Note: I know that won't work, it's just because I typed it in my browser and I'm to lazy to make a longer version (It may work, but it would most likely just scan till ONE is higher then stop, I need the find the highest But it's to messy. Any other ways?
the_lol Onyx user! Joined Mar 19, 2011 Posts 1,766 Reacts 0 Reputation 0 Credits 0 May 12, 2011 #2 What language is this meant to be in?
Automatic User is banned. Joined Mar 19, 2011 Posts 5,304 Reacts 0 Reputation 0 Credits 0 May 12, 2011 #3 the_lol said: What language is this meant to be in? Click to expand... That'd be java...
Chewbaka Well-Known Member Joined Mar 19, 2011 Posts 4,762 Reacts 0 Reputation 0 Credits 0 May 12, 2011 #4 Lol... Put all the variables into an array than use a for loop to go through each one. Since, I am feeling nice. Code: double ARRAY[] = {a, b, c, d, e}; double highestValue = ARRAY[0]; for(int x = 0; x < 5; x++){ if(ARRAY[x] > highestValue){ highestValue = ARRAY[x]; } }
Lol... Put all the variables into an array than use a for loop to go through each one. Since, I am feeling nice. Code: double ARRAY[] = {a, b, c, d, e}; double highestValue = ARRAY[0]; for(int x = 0; x < 5; x++){ if(ARRAY[x] > highestValue){ highestValue = ARRAY[x]; } }
Automatic User is banned. Joined Mar 19, 2011 Posts 5,304 Reacts 0 Reputation 0 Credits 0 May 13, 2011 #5 Chewbaka said: Lol... Put all the variables into an array than use a for loop to go through each one. Since, I am feeling nice. Code: double ARRAY[] = {a, b, c, d, e}; double highestValue = ARRAY[0]; for(int x = 0; x < 5; x++){ if(ARRAY[x] > highestValue){ highestValue = ARRAY[x]; } } Click to expand... Pretty much same thing, I was hoping for a built in function to do it. Guess there isn't one. Feel free to lock.
Chewbaka said: Lol... Put all the variables into an array than use a for loop to go through each one. Since, I am feeling nice. Code: double ARRAY[] = {a, b, c, d, e}; double highestValue = ARRAY[0]; for(int x = 0; x < 5; x++){ if(ARRAY[x] > highestValue){ highestValue = ARRAY[x]; } } Click to expand... Pretty much same thing, I was hoping for a built in function to do it. Guess there isn't one. Feel free to lock.