Sep 5, 2014 at 4:35am UTC
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 Sep 5, 2014 at 4:36am UTC
Sep 5, 2014 at 4:37am UTC
What have you written so far?
If you can do the hello world program, and can do basic math, you are 66% done.
Sep 5, 2014 at 4:41am UTC
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.
Sep 5, 2014 at 4:44am UTC
what is a cast? also, why do you put the centimeters=3.1415926?
Last edited on Sep 5, 2014 at 4:45am UTC
Sep 5, 2014 at 4:46am UTC
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.
Sep 5, 2014 at 4:50am UTC
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
Sep 5, 2014 at 4:52am UTC
is there any way to put it so that the answer is printed out in feet and inches
Sep 5, 2014 at 5:03am UTC
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.
Sep 5, 2014 at 5:13am UTC
Last edited on Sep 5, 2014 at 5:14am UTC
Sep 5, 2014 at 5:20am UTC
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?
Sep 5, 2014 at 5:30am UTC
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.
Sep 5, 2014 at 5:33am UTC
#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
Sep 5, 2014 at 5:53am UTC
For what input? 300?
Print whitespace between values.
Substract the feet from the total.