If you divide an integer by another integer, what you'll get is also an integer, the part after the decimal point is truncated. You should cast one of the integers to float to get a float.
dam = level * ((quality + (chance/10))/100); chance / 10 is 10, quality plus this is 79, and this divided by 100 is 0. level times 0 is again zero and you get zero. You should either say dam = level * ((quality + (chance/10))/100.0); where 100.0 forces the compiler to interpret it as a floating point number rather than decimal or say dam = level * ((quality + (chance/10))/(float)100); ----- Original Message ----- From: "Valnir" <[EMAIL PROTECTED]> To: "ROM List" <[email protected]> Sent: Friday, March 12, 2004 5:00 PM Subject: Floats and Ints. *grumble* > Here is a good one for you guys. If you can tell me why it's messing up, > I'll be forever indebted. > > (some of the items listed below are shown hard coded for readability here) > > /*************************************************************************** > ***************/ > int level = 142; > int quality = 69; > int chance = 100; > float dam; > int damage; > > dam = level * ((quality + (chance/10))/100); > damage = dam / 2; > > if ( damage <= 0 ) > { > sprintf( buf, "Forge: EqLv: %d, Ore Quality: %d, Chance: %d, Dam: %f", > level, quality, chance, dam ); > bug( buf, 0 ); > } > > /*************************************************************************** > ***************/ > > Here is the output from the log: > [*****] BUG: Forge: EqLv: 142, Ore Quality: 69, Chance: 100, Dam: 0.000000 > > HELP!!! > > - Valnir > > > -- > ROM mailing list > [email protected] > http://www.rom.org/cgi-bin/mailman/listinfo/rom >

