Quick question
#1

For example I have this Var[MAX_PLAYERS][Example][5] and Var[playerid][example][1] = 2 and Var[playerid][example][1] = 4 while all the others are 0.How can I find the sum of all these variables without doing this

Var[playerid][example][0] + Var[playerid][example][1] + Var[playerid][example][2].....
Because I use 69 instead of 5 (don't ask) and it will be too long if I use the obvious way
Reply
#2

By using a loop:
pawn Код:
new
    sum;

for (new i; i != 69; ++i) sum += Var[playerid][example][i];
Be sure that you change 69 with the exact size of the last dimension. A higher value can cause run time error: Array index out of bounds.
Reply
#3

pawn Код:
new sum = 0;
for(new n=0; n<69; n++)
{
   sum += Var[playerid][example][n];
}


edit: too late
Reply
#4

Okay thanks I will try it right now. +rep'ed both of you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)