Detecting the smallest variables
#1

Hi,

I have like ex that variables:

Quote:

BLABLA[ playerid ][ 0 ] = 113;
BLABLA[ playerid ][ 1 ] = 106;
BLABLA[ playerid ][ 2 ] = 108;
BLABLA[ playerid ][ 3 ] = 110;
BLABLA[ playerid ][ 4 ] = 95;
BLABLA[ playerid ][ 5 ] = 120;
BLABLA[ playerid ][ 6 ] = 125;
BLABLA[ playerid ][ 7 ] = 135;
BLABLA[ playerid ][ 8 ] = 145;
BLABLA[ playerid ][ 9 ] = 155;

How to check which one is smallest?
Reply
#2

I'm sure there's an easier way, but the simple way I can think of is:
pawn Код:
new smallvar = 0;
for(new i = 0; i < 10; i++)
{
    if(BLABLA[playerid][i] < BLABLA[playerid][smallvar]) smallvar = i;
}
printf("%d is the smallest value.", BLABLA[playerid][smallvar]);
I think there might be an easy way with y_iterate, but I haven't really used that extensively unfortunately.
Reply
#3

Thanks, work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)