HelpHow to find the highest value

Posts 1–5 of 5 · Page 1 of 1
How to find the highest value
How can I find the highest value of 3 items?
Like:

WeaponVote1 = 2;
WeaponVote2 = 0;
WeaponVote3 = 1;
How can I find who is the highest easiest?
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;
}
Quote Originally Posted by master131 View Post
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;
}
Quote Originally Posted by dsds1 View Post
I don't think that this will work for all three, try the calling function
Code:
getHighest(array)
{
    for(i = 0; i < array.size; i++)
        if(array[i] > highest)
            highest = array[i];
    return highest;
}
lol you just have to delete highest = array[0]
But I understand what he means
It WILL work, trust me. It would still work even if the 0th item was not the highest.
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us