# Thread: Ok extremly simple piece of code just to test... help me out

1. ## Ok extremly simple piece of code just to test... help me out

Ok, so I just got a new mac and I am using xcode to do this just to see how it works and this won't work.. it is very very simple, am I just overlooking something? Heres the code.

Code:
```#include <stdio.h>

int main (int argc, const char * argv[]) {
float f, c;

printf("Please enter a temperature in Farenhiet to be converted to Celsius\n");
printf("Temp: ");
scanf(" %f", &f);
c = (5/9) * (f -32);
printf("The temperature in Celsius is: %f \n", c);

return 0;
}```

2. Let me guess: You are always getting zero?

the expression (5/9) is zero, because both sides are integer values, and 5 is smaller than 9, so it goes "zero whole times".

If you change it to say (5.0f/9.0f) it will be a "float" value instead, and thus calcualte to 0.5555555 (or thereabouts).

You could also, if you wanted to do it in integer math, do ((f - 32) *5) / 9. Now only 32 and 33 f turn into 0 c - and this is correct, since that's 0 and 0.55 'C.

I use this formula for "mental" f to c:
c = (f - 30); c /= 2; c += c / 10;

It's not precisely right, but it's pretty close - if it's easier to deduct 32 then I'll do that - but often one degree C won't make any differences either - what's important is if it's above or below zero, and if it's double digits, if it's a 1, 2, 3 or 4 at the beginning.

--
Mats

3. Wow, good guess I was getting 0 every time.. and thanks for the help :]

4. Originally Posted by alexnb185
Wow, good guess I was getting 0 every time.. and thanks for the help :]
Lucky guess, eh? It would of course have been much better if you actually said WHAT was going wrong. [Most new members forget to actually supply that information, and often post 50-100 line pieces of code saying "can you tell me how to fix this" - without actually saying what they want fixed - is it a syntax error, the code crashes (if so when?) or just prints the last line a little bit different from what they expected]. At least your code was understandable within 10 seconds of looking at it, and I could figure out what was the likely problem.

--
Mats

5. Ha, well ok ya I was just wanting to see if like the debugger didn't pick something up I kinda didn't think about the zero thing. Ill make sure to be through next time.