# Converting fahrenheit to celsius but getting 0.00 output

• 09-25-2009
gnozahs
Converting fahrenheit to celsius but getting 0.00 output
For some reason when I input a number in, it comes out 0.00. What did I do wrong? Do I need to int Fahrenheit?

Code:

``` /* Directives */ #include <stdio.h> #include <math.h> int main(void) { float fahrenheit, T; printf("Enter a temperature in Fahrenheit: "); scanf("%f", &fahrenheit); T = (5/9) * (fahrenheit - 32); printf("Celsius is %.2f \n", T); /* End Program */ return(0); }```
• 09-25-2009
mike_g
Code:

`T = (5/9) * (fahrenheit - 32);`
In the red bit you are doing integer maths so the result is 0. As you cant have integer units between 1 and 0 so it rounds down.

Try:
Code:

`T = (5.0f/9.0f) * (fahrenheit - 32.0f);`
• 09-25-2009
Elysia
Although, you only need one of them to be a float to get a proper result.
• 09-25-2009
gnozahs
Ah, no wonder. Thanks so much.

How would I define m/s to ft/s as a constant?

I'm supposed to use 4 significant digits for your conversion factor between m/s to ft/s (which should be defined as a
constant). How would I do this?

My program is outputting 123.45 m/s, but I also need it to say next to the 123.45 m/s, or 405.09 ft/s.

ex: Speed is: 123.45 m/s, or 405.09 ft/s.
• 09-25-2009
tabstop
How do you convert m/s to ft/s?
• 09-25-2009
gnozahs
To go from meters to feet, times meter by 3.28084. But I was wondering if there was a way to make this a constant cause the hw prompt says it should be a constant. Like #define meter to feet 3.28084?
• 09-25-2009
tabstop
If you want. Macro names can't have spaces in them, though.
• 09-25-2009
gnozahs
Ok, so I just put in #define tofeet 3.28084 for the constant and use the word tofeet in my equation.
• 09-25-2009
gnozahs
Thanks for the help!!!