# Thread: Flaoting point question

1. ## Flaoting point question

I can't for the life of me figure out how I'm supposed to use float.
Here's the simple peice of code:
Code:
```  	#include <stdio.h>

int main()
{

int     centimeters;
float  inches;

printf("Enter the number of centimeters you would like converted to feet\n" );

scanf("%d" , &centimeters );

inches = centimeters / (float) 2.54;

printf("The total inches is %d\n", inches );

return 0;
}```
Pretty simple, but I get a crazy number when I input centimeters (something like -1678682734). Any thoughts would be really appreciated, thanks.

P.S. yes I'm a newbie programmer, but hey you gotta start somewhere

2. You need to use %f to print floats. Try changing the %d in your last printf() to a %f.

3. And why do you cast 2.54 to float, when it's already a float? If you wanted to divide centimeters with say 2 (int), then you would either have to cast 2 to float or use 2.0 instead of 2.

4. And why do you cast 2.54 to float, when it's already a float
it's a double actually. For it to be a float you would have to have the "f" at the end. But I'm just being nit picky.

5. Originally Posted by itsme86
You need to use %f to print floats. Try changing the %d in your last printf() to a %f.
Oh ya! D'uh I knew that too, really I did lol.
Anyhow, thank you very much for the feedback. My teacher is a bit of a space case and so I'm sure I'll be back with something like

"What the heck does he mean by that?" or something

hehe

Popular pages Recent additions