SA-MP Forums Archive
Check which is highest - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Check which is highest (/showthread.php?tid=181810)



Check which is highest - CrucixTM - 07.10.2010

Let's say I have 5 distances:

Код:
A = 51.0;
B = 52.0
C = 10.0
D = 12.0
E = 1024.0
I need to find the highest, or the lowest, of these 5. How would I do that? I mean, I can "if(A > B)" but I don't know how to do it with 3 or more values.


Re: Check which is highest - Finn - 07.10.2010

pawn Код:
new Float:distances[] = { 51.0, 52.0, 10.0, 12.0, 1024.0 }; // Set an array with distances
pawn Код:
new highest;
for(new i; i < sizeof(distances); i++) // Loop thru the distances
{
    if(distances[highest] < distances[i]) // Check if the distance is higher than the previous highest distance
    {
        highest = i; // If it is, set this slot to the currently highest distance and continue the loop
    }
}

// Once the loop has ended, 'highest' variable contains the slot that has the highest distance

printf("highest distance is %d (%f)", highest, distances[highest]);
Might help.


Re: Check which is highest - CrucixTM - 07.10.2010

Aaah thanks.