Re: percentile

From: Chaotic (chaotic@eskimo.com)
Date: 02/08/97


On Fri, 7 Feb 1997, Brian Williams - Nashak wrote:

> question... would
> int percent = (GET_HIT(victim) / dam) * 100;
> always return 100?
> I want it so that it'll go into decimals for the division, and then
> * 100 would be the percent of hp you do in damage.. thanks for
> a response =) 

try this brian (it will return 0% if hp <= 0... prevents divide by 0
errors and negative values)

NOTE: written in mailer :)

int get_percent_damage(struct char_data *victim, int damage)
{
     return ( (GET_HIT(victim) > 0)
              ?
              ((dam * 100) / GET_HIT(victim)) : 0
            );
}

so, to use the examples of daniel and mark (25 hp and 2 dam)

    ((2 * 100) / 25) = 8% damage

all in integer arithmetic without using floating point.

enjoy...


+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST