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

Variable Assignment Challenge task 2

I am stuck on the second task...how should it look?

5 Answers

http://teamtreehouse.com/library/variables-2 printf("f A ball with a radius of.\n",A ball with a radius of);

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

The question states: "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".

The video previous to the code challenge shows you how to use format specifiers to print out a string, which means that you will use the variable radius created in the previous step to print out the following response:

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

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.

Hi Bryan Deffinger

Thanks for posting! Could you add a link to the Code Challenge you're referring to, and add the code you're providing as an answer to this Forum post? That would be super helpful. If you're unsure how to add code or links we've provided a Markdown Cheatsheet, found below the new post or reply field, for your convenience. This post is also super helpful! Thank you so much for your help in troubleshooting this issue!

Best,

Elizabeth

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey Bryan, sorry for the delayed response here! You're pretty close, but let's step back and analyze what the challenge is asking for.

Here's our target: "A ball with a radius of 14.5 inches"

Just printing this would require:

printf("A ball with a radius of 14.5 inches");

But the printf function allows for substitution. We want to substitute the variable value for the number. Here's our goal

printf("A ball with a radius of <plug in the value of 'radius' here!> inches");

To do this substitution, we need to use a format specifier:

printf("A ball with a radius of %f inches");

I don't want to give the whole answer away, so for the last part, we provide the value to substitute in by using the variable name. This is included as another parameter in the function, which we include by adding a comma after the statement and then typing the variable name. Review the video if you need to see the final format.

Hope this helps!

This is really new to me and I am a beginner..so the video seems to go really fast. I have watched it over and over again...thanks for all your help.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

It's a lot to take in! It does help to watch things more than once, and the more you practice the more the pieces start to fall into place. Good luck!