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

Printf statement

I have the correct string but not the correct format, any advice?

4 Answers

Kevin Kenger
Kevin Kenger
32,834 Points

Hey Shaun,

What does your code look like?

Hello Kevin its printf("%f a ball with a radius of 14.5 inches")

Kevin Kenger
Kevin Kenger
32,834 Points

OK you're close, and you've included %f in the statement, which is great. But in order for the code to work properly, you need to swap out 14.5 for %f. That way it takes the value of the float variable, and inserts it into your statement. Then, after your final quotation mark, you add a comma, then specify exactly which float variable to get.

Like this:

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

My aha moment that made sense thanks kevin

Kevin Kenger
Kevin Kenger
32,834 Points

Awesome, I love those! You're very welcome!