decPlace_volume = floor(volume+.05) - ceil(volume); //should output -1, 0, or 1
decPlace_volume = pow(decPlace_volume,2); //should the above == -1, this should turn it into 1 while making 0 remain 0
The only allowed libraries for my assignment are stdio.h and math.h.
My assignment is pretty simple - find the surface area and volume of a cylinder, and the precision of the output should be 1 unless the output decimal would be 0, in which case the decimal shouldn't be printed.
The above is what I came up with (same thing for surface area just different variables). If the output of the first line is -1, the second line should make it positive, and 0 should stay zero (integer so shouldn't need to worry about funky stuff).
For some reason, when the first line outputs a 0, the second line is outputting 1. Is there something I'm missing here?
Your question asks to suppress the decimal if it would be
0
, here is one way to do thatProgram output: