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 trialFrank Truglio
10,759 Pointsprintf statement a ball with a radius of... not understanding the input required
Add a printf statement to print the radius variable. Here is what your output should look like: A ball with a radius of 14.5 inches.
2 Answers
Stone Preston
42,016 Pointswhen using printf with format specifiers and variables, the variable shows up in place of the format specifier. If i had a variable named numberOfCows that had the value 3 and wanted to print it out in a string I could use
printf("There were %d cows on the moon", numberOfCows);
it would output: "There were 3 cows on the moon". See how the value of the variable shows up in the string where the format specifier was? You can apply the same principles above to this challenge, except instead of using %d (ints) you would use %f (for floats)
Marwi M
1,411 Pointsfirst : deside the type of data to be displayed. in your case "14.5" , which is float type. we represent float in the printf string by %f. second: printf("the variable value is %f",var);// the text will be printed and instead of %f it will print the value of var
hope that helps you ,