Find highest value?

Automatic

User is banned.
Reputation
0
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 language is this meant to be in?
 
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];
    }
}
 

Pretty much same thing, I was hoping for a built in function to do it. Guess there isn't one.

Feel free to lock.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…