public void c2f(){
int cm = readInt("Please enter cm: ");
double feet = cm/30.48;
double inches = (cm/2.54) - (feet * 12);
println("There are " + feet + " feet and " + inches + " inches in " + cm + "cm");
}
Okay, so I'm trying to make a cm to feet and inches conversion here, and I've tried to make it so that it displays feet and inches, but I'm not having any luck since if I put in, for example 180cm, it comes out with 5.9 feet and 0.0 inches, how can I change it do that it will put out 5 feet and x inches?
Thanks in advance.
---------- Post added at 03:15 AM ---------- Previous post was at 02:35 AM ----------
It's okay, I solved it.
public void c2f(){
int cm = readInt("Please enter cm: ");
double feet = cm/30.48;
double inches = (cm/2.54) - ((int)feet * 12);
println("There are " + (int)feet + " feet and " + inches + " inches in " + cm + "cm");
}
Just needed to cast feet as an integer :)


Sign In
Create Account

Back to top









