Converting an integer - 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: Converting an integer (
/showthread.php?tid=626376)
Converting an integer -
Rufio - 14.01.2017
As stupid as it may sound, is it possible to convert an integer to a double value? Here is the code;
pawn Код:
new bki[MAX_PLAYERS];
new boymetre[MAX_PLAYERS];
new boycarpimi[MAX_PLAYERS];
boymetre[playerid] = pInfo[playerid][Boy] / 100;
boycarpimi[playerid] = boymetre[playerid] * boymetre[playerid];
bki[playerid] = pInfo[playerid][Kilo] / boycarpimi[playerid];
new kiloluluk[MAX_PLAYERS];
printf("%d",boymetre[playerid]);
printf("%d",boycarpimi[playerid]);
printf("%d",bki[playerid]);
if(bki[playerid] > 0.0 && bki[playerid] < 30.0) // obez degil
kiloluluk[playerid] = 0;
else if(bki[playerid] >= 30) // obez
kiloluluk[playerid] = 1;
What this code is supposed to do is to calculate the BMI according to the data the player has provided. The issue is, as you may already have guessed boymetre returns an integer value(mostly 1 or 2 depending on the height the player has provided in cm). I am actually a C programmer and I tried to do it the way C does it;
pawn Код:
new bki[MAX_PLAYERS];
new boymetre[MAX_PLAYERS];
new boycarpimi[MAX_PLAYERS];
boymetre[playerid] = pInfo[playerid][Boy] / 100.0;
boycarpimi[playerid] = boymetre[playerid] * boymetre[playerid];
bki[playerid] = pInfo[playerid][Kilo] / boycarpimi[playerid];
new kiloluluk[MAX_PLAYERS];
printf("%d",boymetre[playerid]);
printf("%d",boycarpimi[playerid]);
printf("%d",bki[playerid]);
if(bki[playerid] > 0.0 && bki[playerid] < 30.0) // obez degil
kiloluluk[playerid] = 0;
else if(bki[playerid] >= 30) // obez
kiloluluk[playerid] = 1;
But then I got this warning;
Код:
C:\Users\Asus\Desktop\Yigit proje 1\gamemodes\Survival_MySQL.pwn(965) : warning 213: tag mismatch
965th line is this;
pawn Код:
boymetre[playerid] = pInfo[playerid][Boy] / 100.0;
My question is, is it possible to convert an integer value to a double or a float value, if so, how? Thanks in advance.
Re: Converting an integer -
BiosMarcel - 14.01.2017
https://sampwiki.blast.hk/wiki/Float
Re: Converting an integer -
SyS - 14.01.2017
Just declare boymetre[MAX_PLAYERS]; with Float: tag the compiler will do the implicit conversion to greater data type(sounds lame as pawn doesn't any data type but i'm explaining it in c style so as make it understandable to you).
Re: Converting an integer -
Rufio - 14.01.2017
Quote:
Originally Posted by [Bios]Marcel
|
How foolish of me lol, thanks
Quote:
Originally Posted by Sreyas
Just declare boymetre[MAX_PLAYERS]; with Float: tag the compiler will do the implicit conversion to greater data type(sounds lame as pawn doesn't any data type but i'm explaining it in c style so as make it understandable to you).
|
Thanks a lot!