Hey guys, I want to know what I did wrong for my Fahrenheit to Celsius function to calculate the wrong answer. Example: If I input 0 degrees for Fahrenheit it results in -0 degrees Celsius. What's causing this? Celsius to Fahrenheit on the other hand seems to work perfectly. I don't know what gives... :-(
There is something in the syntax of the equation...
I put DEGc = (((degreeF - 32) * 5) / 9); and DEGf = (degreeC * 9)/5 + 32; and got the expected result.
If someone could explain this... =D
***The celsius to fahrenheit isn't correct, it gives the wrong answer too.
***EDIT***
Yeah, it's the syntax.
Look at this: DEGc = ((degreeF-32)*(5/9));
In this format, the code'll divide 5 with 9 and subtract 32 of degreeF at the same time... BUT you are dividing to integers numbers (5 and 9), so the result printed by the program is an INTEGER VALUE. Dividing 5 with 9 you have 0.5555, but the code'll print only 0. When degreeF-32 multiplies 0 the result is 0 always.
The same logic happens with celsius to farenheit.
Yes that definitely helped and fixed the issue. So generally, when using double and using mathematical calculations, one should use a decimal point to differentiate it from an integer value? :)
> So generally, when using double and using mathematical calculations, one should use a decimal point to differentiate it from an integer value? :)
Yes :)