C program to convert Fahrenheit to Celsius always prints zero
5/9 will result in integer division, which will = 0
Try 5.0/9.0
instead.
You problem is here :
celsius = (5/9) * (fahrenheit-32);
5/9
will always give you 0
. Use (5.0/9.0
) instead.
try celsius = ((double)5/9) * (fahrenheit-32);
Or you can use 5.0.
The fact is that "/" looks at the operand type. In case of int the result is also an int, so you have 0. When 5 is treated as double, then the division will be executed correctly.