Discussion Locked

Simple C Program Math Problem.

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Program - Microsoft Visual Studio
Win98

I am attempting to write a program that will convert Celsius to Fahrenheit.
the formula to do this is F= 9 / 5 * C + 32

after inputting 10 as Celsius (which is 50 F)
i kept gettin the answer 42.
i changed the formula to see where it was going wrong, and discovered that it was calculating the answer to 9/5 as 1.0, which is obiously wrong.
it should be 1.8.
it also calculates 9/4 as 2.0 ?????

Any ideas that will help me for the points?

5 replies

by mikenac

Here you go:

float CelsiusToFahrenheit ( float cel )
{
float fahr;

fahr = ( 9.0/5.0 * cel ) + 32;
return ( fahr );
}

Although you should really convert the floats to double.

by mckay_w

Dont understand how and why that worked, but it did.
I've only just started learning C, not fully got everything down pat yet.
Thankyou.
mckay_w@hotmail.com

This discussion is closed to new replies.