Re: [Circle] [NEWBIE] stupid code question

From: Charles Canning (charles@engr.mun.ca)
Date: 08/19/96


Hi,

On Sun, 18 Aug 1996 grond@grotl.com wrote:

> Ok I know I've missed something totally idiotic with this one, but....
> 
> I'm trying to get the damage you do when you hit a victim to give some
> additional clues to the other user on how damaged the victim is.
> 
> I've added the following snippet of code to fight.c
> ------------
> 
> int percent;
> 
> percent = (GET_HIT(victim) / GET_HIT_MAX(victim)) * 100

This will always evaluate to zero because the integer type cast of any 
decimal is zero. A cast to int or using integers always truncates the 
decimal value. A solution would be to multiply by 100 before you divide.

percent = (100 * GET_HIT(victim) / GET_HIT_MAX(victim));B


Later...

> 
> followed by a number of if statements on what to do with various percent
> levels.
> 
> Problem is, it's getting the right GET_HIT and GET_HIT_MAX values but
> not doing anything in percent.
> 
> Percent continues to show 0 and doesn't change.
> 
> Ok, what has the newbie missed here.
> 
> Grond
> 
> SENT FROM: GAME ROOM ON THE LAKE BBS (GROTL.COM)
> YOUR PLACE FOR ONLINE ENTERTAINMENT
> PHONE: (704) 664-6742
> 
> 
> +-----------------------------------------------------------+
> | Ensure that you have read the CircleMUD Mailing List FAQ: |
> |   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
> +-----------------------------------------------------------+
> 
+-----------------------------------------------------------+
| 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/07/00 PST