Why wont this work? (kind of math formula) - 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)
+--- Thread: Why wont this work? (kind of math formula) (
/showthread.php?tid=403340)
Why wont this work? (kind of math formula) -
101 - 30.12.2012
pawn Код:
new robmoney = (400-rob[id])/4)*3);
GivePlayerMoney(playerid, robmoney);
error 001: expected token: ";", but found ")"
Re: Why wont this work? (kind of math formula) -
Threshold - 30.12.2012
You're just missing a few brackets, they amount of end brackets must equal the same as the beginning brackets.
Beginning = (
Ending = )
Your code:
pawn Код:
new robmoney = (((400-rob[id])/4)*3);
GivePlayerMoney(playerid, robmoney);
Re: Why wont this work? (kind of math formula) -
101 - 30.12.2012
Holy mother of god, how could I miss that! Thanks bro.
AW: Why wont this work? (kind of math formula) -
Nero_3D - 30.12.2012
Another important thing if you do maths with integer, always use the division as last!
Lets check out this example, normally you would think it works like that
158 / 4 * 3 = 39.5 * 3 = 118.5
158 * 3 / 4 = 474 / 4 = 118.5
But the truth is that the fractional part is cut off each time resulting in
158 / 4 * 3 = 39.5 * 3 => 39 * 3 = 117
158 * 3 / 4 = 474 / 4 = 118.5 => 118
pawn Код:
new robmoney = (((400 - rob[id]) * 3) / 4);
Re: Why wont this work? (kind of math formula) -
Threshold - 30.12.2012
Unless you made it a float value.
AW: Re: Why wont this work? (kind of math formula) -
Nero_3D - 30.12.2012
There is no reason to make it a float if you need an integer afterwards
And if you would use floats that you just could do * 0.75 (one operation) instead of * 3 / 4 (two operations)