calculating problem
#1

Hi
i have a problem
i want to make a skill percentage according to player kills and player deaths
this is my code i think all should work correctly but it just shows 0%
Код:
GetPlayerLevel(playerid)
{
	new  asb,Shotor,agoz,bgoz,sumi,aall;
	asb = PlayerInfo[playerid][pKills];
	Shotor = PlayerInfo[playerid][pDeads];
	agoz = asb - Shotor;
	bgoz = asb + Shotor;
	sumi = agoz / bgoz;
	aall = sumi * 100;
	return aall;
}
whats the problem?
Reply
#2

The variable are of int (integer) type which do not store decimal places. Thus when you do "sumi = agoz / bgoz;", the answer is probably in decimals which gets truncated to 0 always as it is integer type.

Declare 'aaall' and 'sumi' as float.
Like this :
Quote:

new asb,Shotor,agoz,bgoz,Float:sumi,Float:aall;

Reply
#3

you have to give a check whether agoz or bgoz is greater and do the division because an integer division having result having less than 1 is round to 0 and the result will be zero.
PHP код:

GetPlayerLevel
(playerid)
{
    new  
asb,Shotor,agoz,bgoz,sumi,aall;
    
asb PlayerInfo[playerid][pKills];
    
Shotor PlayerInfo[playerid][pDeads];
    
agoz asb Shotor;
    
bgoz asb Shotor;
    if(
agoz>bgoz)
    
sumi agoz bgoz;
    else
    
sumi bgoz agoz;
    
aall sumi 100;
    return 
aall;

or declaring the vars as floats can avoid it.
Reply
#4

If only you didn't use animals and fart as variable names
If it's a percent, you need to use float-float divisions to work it out.
new Floatumi = float(agoz)/float(bgoz) *100.0;

or you could do agoz*100 / bgoz, which still give a percent, but with a margin of error.
Reply
#5

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
If only you didn't use animals and fart as variable names
If it's a percent, you need to use float-float divisions to work it out.
new Floatumi = float(agoz)/float(bgoz) *100.0;

or you could do agoz*100 / bgoz, which still give a percent, but with a margin of error.
thanks buddy +Rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)