Decimal Places/Conversion

Hey!

I have to write a program where centimeters is converted to feet and inches. For example, the input is 333.3 cm, the output should be 10 ft and 11.2 inches. I already have written the program as follow;


#include <stdio.h>
#include <stdlib.h>
#define In 2.54
#define Ft 12

void main ()

{
int a;
float X;
printf ("\nEnter the value to be converted: ");
scanf ("%d", &a);
X=(a/In/Ft);
printf ("The area: %5.2f\n", X);
getch ();

}

The result I got for 333.3 cm is 10.93. My question is how to convert that 0.93 to 11.2 inches. Any response will be truly appreciated. Thank you!

0.93 * numberOfInchesInAFoot
I mean the output should be 10 ft 11.2 inches. So if I input another number the result should be in that format.. in ___ ft ____ inches. Thank you.
You're using C funtions, is that intentional?

Take a look at fmod() and modf() in the math.h library

http://www.cplusplus.com/reference/clibrary/cmath/fmod/
http://www.cplusplus.com/reference/clibrary/cmath/modf/

you'll need another variable to store the inches
Last edited on
Thank you! Will try what you suggested. Thanks
Topic archived. No new replies allowed.