The values '5' and '9' are integers and 5/9 is considered as 0
instead of 0.55
which is why you get the wrong answer. When two integers are divided, the answer is floor()
automatically. It is necessary to write either one of '5' and '9' as 5.0 and 9.0
A better practice is to always write both as 5.0
and 9.0
or write them as double(5)
and double(9)
Since multiplication and other operations are mostly left recursive, this statement would work fine as well.
(fahrenheit-32)*5/9;
as the statement starts with a double value