centimeters to feet and inches conversion

Given as input a floating (real) number of centimeters, print out the equivalent number of

feet (integer) and inches (floating, 1 decimal), with the inches given to an accuracy of one

decimal place.

Assume 2.54 centimeters per inch, and 12 inches per foot.

Input

333.3

Output

333.3 centimeters is 10 feet 11.2 inches.

I have no idea how to do this problem. Can someone show how to do this problem?
Last edited on
What have you written so far?

If you can do the hello world program, and can do basic math, you are 66% done.
I have done that already, and I also know how to do the math symbols. But, I don't know which way to do so that I can separate the decimal part from the feet.
You can perform a cast:
1
2
double centimeters = 3.1415926;
int feet = static_cast<int>(centimeters / 2.54);
what is a cast? also, why do you put the centimeters=3.1415926?
Last edited on
I just showed you. It performs a (possibly lossy) conversion from an undesired type to a desired type. It can only be used when compatible with the types in question.
this is my code so far:
#include <cstdio>
#include <iostream>
#include <iomanip>
using namespace std;
int main ()

{
double feet, inches, centimeters ;
centimeters = 3.1415926;
feet = static_cast<double>(centimeters / 2.54);
cin >> centimeters;
cout << setprecision(1)<< feet << centimeters;

}

my result:
13e+002
is there any way to put it so that the answer is printed out in feet and inches
I can do all the code up to the part where you have it converted to ab.cde feet. After that, I do not know how to subtract just the ab.
http://www.cplusplus.com/forum/general/141817/#msg748826
LB wrote:
You can perform a cast:
1
2
double centimeters = 3.1415926;
int feet = static_cast<int>(centimeters / 2.54);
Last edited on
The only problem I have is that when I integrate that into my code, I get the error. So right now I can only ponder on how to solve it after I get the ab.cde feet. Can you show me the entire code that you wrote which works without errors?
No. You have the right to learn.

The second line of LB's example tells how many inches are in the centimeters.

Your code has same line before you even know the value of centimeters.
#include <cstdio>
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
double feet, inches, centimeters ;
centimeters = 3.1415926;
cin >> centimeters;
feet = static_cast<double>(centimeters / 2.54);
cout << setprecision(1)<< feet << centimeters;

}
still, my result is this: 1e+0023e+002
For what input? 300?

Print whitespace between values.

Substract the feet from the total.
Topic archived. No new replies allowed.