Pawn with formula calculation
#1

I'm currently testing a formula to work out an incrementing value based on what number is entered but for some strange reason what is output is completely different from what should output. I'm just wondering if there is a specific way I need to format this for pawn that I'm doing wrong?

EDIT: TL; DR version, I need this PHP code converted to pawn.

I'm basing this off a php formula I found, which works 100%. Test it here if you need to http://writecodeonline.com/php/
Код:
function formula($L) {
  $a=0;
  for($x=1; $x<$L; $x++) {
    $a += floor($x+300*pow(2, ($x/7)));
  }
  return floor($a/4);
}

for($L=1;$L<100;$L++) {
  echo 'Result '.$L.': '.formula($L).'<br />';
}
This is my command for testing the formula
pawn Код:
CMD:checkformula(playerid, params[])
{
    new Float:formula, Float:result, string[128];
    for(new i = 1; i<4; i++)
    {
        formula = (i+300*(floatpower(2, i/7)));
        result = (formula/4);
        format(string, sizeof(string), "For Input: %i, Formula = %i, Result = %i", i, floatround(formula), floatround(result));
        SendClientMessage(playerid, 0xCCFF00AA, string);
    }
    return 1;
}
What outputs:
Код:
For input: 1, Formula = 301, Result = 75
For input: 2, Formula = 302, Result = 76
For input: 3, Formula = 303, Result = 76
What should output but doesn't:
Код:
For input: 1, Formula = 332, Result = 83
For input: 2, Formula = 699, Result = 174
For input: 3, Formula = 1105, Result = 276
Reply


Messages In This Thread
Pawn with formula calculation - by V1ceC1ty - 27.09.2014, 11:33
Re: Pawn with formula calculation - by thefatshizms - 27.09.2014, 11:39
Re: Pawn with formula calculation - by V1ceC1ty - 27.09.2014, 11:45
Re: Pawn with formula calculation - by thefatshizms - 27.09.2014, 11:52
Re: Pawn with formula calculation - by V1ceC1ty - 27.09.2014, 12:03
Re: Pawn with formula calculation - by Vince - 27.09.2014, 12:08
Re: Pawn with formula calculation - by V1ceC1ty - 27.09.2014, 12:09
Re: Pawn with formula calculation - by thefatshizms - 27.09.2014, 12:28
Re: Pawn with formula calculation - by V1ceC1ty - 27.09.2014, 12:31
Re: Pawn with formula calculation - by thefatshizms - 27.09.2014, 12:41

Forum Jump:


Users browsing this thread: 1 Guest(s)