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 trialBryan Deffinger
359 PointsVariable Assignment Challenge task 2
I am stuck on the second task...how should it look?
5 Answers
Bryan Deffinger
359 Pointshttp://teamtreehouse.com/library/variables-2 printf("f A ball with a radius of.\n",A ball with a radius of);
Bryan Deffinger
359 PointsAdd 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.
ecp
838 PointsThanks 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
Treehouse TeacherHey 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!
Bryan Deffinger
359 PointsThis 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
Treehouse TeacherIt'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!
Amit Bijlani
Treehouse Guest TeacherAmit Bijlani
Treehouse Guest TeacherThe 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);