Re: [Help] Math Error?

From: Chris Hyde (slugger@CRYOGEN.FERRIS.EDU)
Date: 04/12/98


> 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)?

Well, the formula above works out to be (6/19) + .5 = .815...

I don't think casting integers does any rounding, but I could be wrong, so
what is happening is the decimal result is being dropped, and only the
integers on the left of the . are being used for the value of msgnum(which
in this case there are no integers, so the value returned is zero).


     +------------------------------------------------------------+
     | 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