SA-MP Forums Archive
a problem that i wont solve in 5 mins after posting this - 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: a problem that i wont solve in 5 mins after posting this (/showthread.php?tid=251153)



a problem that i wont solve in 5 mins after posting this - DeadAhead - 25.04.2011

(hopefully)

this one doesn't work :O

stock GetHighestNumberEx(num[])
{
new highesty = 0;
for (new i = 0; i<sizeof(num[]);i++)
{
if (num[i] > highesty) { highesty = num[i]; printf("%d > %d",highesty,num[i]); }
}
return highesty;
}

Suposed to loop throught an array to find the highest number. I tried many arrays, but it seems to allways return 0.
any idea why?


Re: a problem that i wont solve in 5 mins after posting this - JaTochNietDan - 25.04.2011

Your sizeof won't work like that, I was able to fix it by adding an additional parameter called size which defaults to the size of the first parameter using sizeof, tested and it works fine.

pawn Код:
stock GetHighestNumberEx(num[], size = sizeof(num))
{
    new highesty = 0;
    for (new i = 0; i < size; i++)
    {
        if (num[i] > highesty) { highesty = num[i]; printf("%d > %d",highesty,num[i]); }
    }
    return highesty;
}
Tested with:

pawn Код:
new array[] = {1,4,2,1,4,55,242,2,1,4,22};

printf("Highest is %d", GetHighestNumberEx(array));
Hope that helps


Re: a problem that i wont solve in 5 mins after posting this - DeadAhead - 25.04.2011

o.o Thanks. Really didnt script in a long time mate, thanks.