SA-MP Forums Archive
Integer variable comparison - 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: Integer variable comparison (/showthread.php?tid=168425)



[SOLVED]Integer variable comparison - Jakku - 16.08.2010

I have a little question.


I have to compare four integer variables, and get which of them has the smallest value

pawn Code:
new variable[4];


if (variable[1] < variable[2] < variable[3] < variable[4]) //This IS NOT what I am looking for

How could I do that?


Re: Integer variable comparison - wups - 16.08.2010

pawn Code:
new variable[4];

stock WhichIsSmallest(variable1,variable2,variable3,variable4)
{
if(variable1 < variable2 && variable1 < variable3 && variable1 < variable4) return 1;
else if(variable2 < variable1 && variable2 < variable3 && variable2 < variable4) return 2;
else if(variable3 < variable1 && variable3 < variable2 && variable3 < variable4) return 3;
else return 4;

}



Re: Integer variable comparison - Jakku - 16.08.2010

Yea, thanks