1. ## Variable help

hello everyone, im new to the whole programing thing, and I seem to be having problems with multiplying/dividing multiple integers.
The line that is giving me all the problem is
Code:
`printf( "Message: %d", int1 * ( int2 / int3 );`
I have defined all three variables, and have it set up so the user enters all 3 ints, and then the program spits out the number. most of the time, int2 / int3 gets me a irrational number, (such as 1.66666666), then multiplies it by int1, usualy resulting in a integer.
the only problem is that im trying to make the program work even when the output number is 199.99999, so how would i go about doing this? mabye rounding the out put to the nearest integer?

2. What do you mean? If the result is 199.99999 then that is what you want to see or do you want to see the rounded integer value? Integer division will truncate anything after the decimal point, i.e 8/5 = 1, which will screw up your expected results. If you need to work with floating point value then use float/double variables instead of int variables.

3. Originally Posted by hk_mp5kpdw
What do you mean? If the result is 199.99999 then that is what you want to see or do you want to see the rounded integer value? Integer division will truncate anything after the decimal point, i.e 8/5 = 1, which will screw up your expected results. If you need to work with floating point value then use float/double variables instead of int variables.
Or, you can use a typecast (and change the format to float, or cast it back to integer later):
Code:
`printf( "Message: %f", int1 * (float)( int2 / int3 ));`
or
Code:
`printf( "Message: %d", (int)(int1 * (float)( int2 / int3 )));`
--
Mats

4. Thx much everyone, its working now.
i changed int2 and int 3 to floating point, and used matsp's 2nd code line