Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Fundamentals of C Variables

Frank Truglio
Frank Truglio
10,759 Points

printf 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
Stone Preston
42,016 Points

when 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
Marwi M
1,411 Points

first : 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 ,