How can I find the highest value of 3 items?
Like:
How can I find who is the highest easiest?Quote:
WeaponVote1 = 2;
WeaponVote2 = 0;
WeaponVote3 = 1;
Printable View
How can I find the highest value of 3 items?
Like:
How can I find who is the highest easiest?Quote:
WeaponVote1 = 2;
WeaponVote2 = 0;
WeaponVote3 = 1;
Use an array like this:
Code:something()
{
weaponVote = [];
weaponVote[0] = 2;
weaponVote[1] = 0;
weaponVote[2] = 1;
highest = getHighest(weaponVote); //This will make highest equal to 2
}
getHighest(array)
{
highest = array[0];
for(i = 0; i < array.size; i++)
if(array[i] > highest)
highest = array[i];
return highest;
}
I don't think that this will work for all three, try the calling function
Code:getHighest(array)
{
highest = array[0];
highest2 = array[2];
for(i = 0; i < array.size; i++)
if(array[i] > highest)
highest = array[i];
else if(array[i] > highest2)
array[i] = highest;
else
array[i] = highest;
return highest;
}
It WILL work, trust me. It would still work even if the 0th item was not the highest. =|