Converting an integer
#1

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

https://sampwiki.blast.hk/wiki/Float
Reply
#3

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).
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)