Look. You are stepping into type conversion problems. You are THINKING with floats (real numbers, fractions, decimels, dollars AND cents) but you are WORKING with ints (integers, whole number, dollars ONLY). The ONLY way to get it to work properly is to cast it something like: z = ((float)(x)); OR to force the ints into floats by using a float constant, like: z = 10 * 50.0; If you ONLY use ints, your answer will ONLY be an int. If you use ANY floats, your answer will be a float. Next lesson. int x; float y; y=.9; x=y; What is x? Answer: 0. Why? X is an int, a whole number. When you assign a float value to an int, you truncate the decimals. int x; x = 10/2; What is x? 5. x = 10/3; What is x? 3. x = 49/50; What is x? 0. So, basically unless you force your division into floats, you will be dividing by 0 each time any char has less than 100% health. You can force it to float using a cast, or by using a float constant (50.0) Helver On Tue, 23 Jul 1996, Adam Days wrote: > Okay I came up with a new way to do it, and I don't think it divides by > zero in any way shape or form, but it still doesn't work. > > how 'bout this: > > int i; > float val; > int z; > > z = GET_HIT(ch) * 50; /* always a whole number */ > val = z / GET_MAX_HIT(ch); /* here is where it gets into a decimal */ > > for(i=0; i <= val; ++i) > *(buf2 + i) = '*'; > *(buf2 + i) = '\0'; > > sprintf(buf, "[ %-50s ] LIFE METER\r\n", buf2); > send_to_char(buf, ch); > > shouldn't this work? I tried it but it still messes up. same Arithmetic > Exception. I'm not still dividing by zero am I? > ******************************************************************************* > Adam Days a.k.a ** "Being an Outcast is only a frame of mind > Drizzt Do'Urden ** and not something that is placed upon > Unholy Lands <164.116.34.2 4000> ** you." -Adam Days > ******************************************************************************* > > >
This archive was generated by hypermail 2b30 : 12/07/00 PST