Why is PAWN returning the wrong answer? - 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: Why is PAWN returning the wrong answer? (
/showthread.php?tid=258445)
Why is PAWN returning the wrong answer? -
pagie1111 - 30.05.2011
I was curious to something, and decided to use PAWN to work out the speed (dont ask why I was just bored)
I ran this:
pawn Код:
#include <a_samp>
main()
{
new Float:dis=0.1,
Float:time=3600,
Float:speed = 0;
speed = (dis/time);
printf("%d",speed);
}
which returned 938017875
How is that possible?
distance is KM so 0.1 KM = 100 mtrs
time is seconds so 3600 seconds is 1 hour
When I put this in my calculator I get 0.000027777
Is this because there is a limitation to pawn that it can't give out 0.000027777?
But then I run it like this:
pawn Код:
#include <a_samp>
main()
{
new Float:dis=1.0,
Float:time=1.0,
Float:speed = 0;
speed = (dis/time);
printf("%d",speed);
}
and I get answer 1065353216
but 1.0/1.0 = 1
what is happening here? Im really confused..
Re: Why is PAWN returning the wrong answer? -
RyDeR` - 30.05.2011
"speed" variable is a Float not an integer. Use '%f' instead of '%d'.
Re: Why is PAWN returning the wrong answer? -
pagie1111 - 30.05.2011
OH shit... LOL!
OMFG how was I that stupid. HAHA thanks RyDER'.
Re: Why is PAWN returning the wrong answer? -
Sasino97 - 30.05.2011
%f
edit: too late XD
Re: Why is PAWN returning the wrong answer? -
pagie1111 - 30.05.2011
Now this is starting to make more sence.. lol I am trying to work on a speed system for my Sam Site script. I was trying to wonder how fast i'd have to make a missile go to kill a target 300mtrs away in 10 seconds and it returned something stupid.. I was like WTF?
Then i dumbed it down to 0.1/0.1 and then whadda you know? lol
answer is 108km/h