Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Vijesh Arora
Front End Web Development Techdegree Student 34 PointsConverting cm to feet and inches?
I wrote the code to convert cm to feet and inches but I am getting double value like 6.3434 feet and 1.34344 inches instead of 6 feet and 1 inches.
Here is my code:
public static void main(String[] args) {
heightinc(155);
}
public static double heightinc(double centimeters){
double feet;
double inches;
inches = centimeters / 2.54;
feet = inches / 12;
double delta = inches - (feet * 12);
System.out.println("I estimate your height to be " + feet + " feet and " + inches + " inches ");
return delta;
}
2 Answers
Philip Gales
15,193 PointsFirst off, the code you provided passes 155. What is the output you are seeing when passing 155? Also, what do you pass into your method when you are trying to get the 6 and 1 answer?
I am sure it was a mistake, but until you can provide the exact code for the output, no one will be able to assist you.
Philip Gales
15,193 PointsIt appears your input is the problem. Try changing the 155 to something else and it will give exact answers.
Vijesh Arora
Front End Web Development Techdegree Student 34 PointsVijesh Arora
Front End Web Development Techdegree Student 34 PointsThe output came like this - Your height is 5.085301837270341 feet and 61.023622047244096 inches..
You can look at the screenshot here - http://prnt.sc/dnpltd