Why wont this work? (kind of math formula)
#1

pawn Код:
new robmoney = (400-rob[id])/4)*3);
        GivePlayerMoney(playerid, robmoney);
error 001: expected token: ";", but found ")"
Reply
#2

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);
Reply
#3

Holy mother of god, how could I miss that! Thanks bro.
Reply
#4

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);
Reply
#5

Unless you made it a float value.
Reply
#6

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)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)