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

Hello, I was trying to type a printf statement in the Challenge task 2. I stuck on this step. Cannot move further.

float radius = 14.5;

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

2 Answers

Stone Preston
Stone Preston
42,016 Points

here is your issue:

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

First, you dont need to return 0. Only provide what the challenge asks for.

Secondly, you need to use a format specifier in place of the 14.5 in your string. Using a format specifier allows you to insert the values of variables into a string. In this case you have created a variable called radius. You want to be able to display that variable in the string, not just a static value.

You can print a string with the value of a variable in it like so:

float someVariable = 10.0;
printf("This is a string with this variable's value of: %f inside it", someVariable);

which will output This is a string with this variable's value of: 10.0 inside it.

in your case, you need to print the variable where you currently have 14.5, so just replace 14.5 with %f, and add a comma and the variable name, radius, after it as shown in the example above.

Hi Stone, Thank you very much for your explanation. It was very helpful. Many thanks, Elmira