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

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

Mike Grady
Mike Grady
197 Points

printf

I am having trouble with the printf statement for the 14.5 radius

Stone Preston
Stone Preston
42,016 Points

what have you tried so far?

2 Answers

Stone Preston
Stone Preston
42,016 Points

printf statements generally look like this:

printf("This is a variable with a value of %f that will be printed", someVariable);

the value of someVariable will be inserted into the string where the format specifier is (%f in this case). you use %f for floats, %d for ints, %c for chars, and there is a lot more as well.

you are almost correct. use double quotes around your string, and instead of using 14.5 use a format specifier. also your \n escape sequence is missing the n. you also forgot to close your string. fixing all that leads to this:

float radius = 14.5;
printf("A ball with a radius of %f inches.\n", radius);

since the variable you want to print is a float, you use %f as the format specifier

Mike Grady
Mike Grady
197 Points

float radius = 14.5; printf('A ball with a radius of 14.5 inches.\, radius);