Why is PAWN returning the wrong answer?
#1

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..
Reply
#2

"speed" variable is a Float not an integer. Use '%f' instead of '%d'.
Reply
#3

OH shit... LOL!

OMFG how was I that stupid. HAHA thanks RyDER'.
Reply
#4

%f

edit: too late XD
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)