Re: [Help] Math Error?

From: Ron Cole (rcole@SHELL.EZY.NET)
Date: 04/12/98


> I realize that this is not really too CircleMUD related,
> but would someone mind helping me out with this problem.
>
> Given:
> int top_of_dam_messt = 18;
> int perc_hit = 6;
>
>   msgnum = (int)(((perc_hit)/(top_of_dam_messt + 1)) + 0.5);
>
> Why does msgnum keep coming out to Zero (0)?

Integer math... decimals are dropped at every step:  6/19 = 0, +.5 = 0.
Do the math in a float first, then drop it back to int.

Ron


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



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