Percent problem.

BlitzMax Forums/BlitzMax Beginners Area/Percent problem.

WERDNA(Posted 2010) [#1]
Hey everyone!

I have a quick question about how to calculate percents.

I have two variables in my game, one which keeps track of how
many times you attack, and the other which keeps track of how
many times you hit with your attack. What I want to do, is figure
out what percent of the attacks hit.

I.e, lets say you fire off 233 attacks and hit with 154.

What percent of 233 is 154?

If someone could answer this, that would be great ;)


GfK(Posted 2010) [#2]
Clues in the question - you hit 154/233 times.

pc = (float(hits)/attacks) * 100


Remember that either hits OR attacks needs to be converted to a float, otherwise you'll always get 0 as the result if both sides are integer.


WERDNA(Posted 2010) [#3]
Ok!

Thanks Gfk, much appreciated :)