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 trialLewis Davidson
694 Pointshelp with printf for a float radius early lesson question
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.
float radius = 14.5;
printf("a ball with radius. \n" ball_with_radius);
3 Answers
Thomas King
15,197 PointsDid you just want to print the radius? Then you need to properly call the variable inside of the print statement like this:
float radius = 14.5;
printf("A ball with radius %f. \n", radius);
Make the call to a float variable (the %f in the statement), separate the output with a comma, then point to the variable you wish to declare in the statement (&radius).
Logan R
22,989 PointsYou forgot the , after the string in printf, but more importantly, you are using the wrong variable in the printf. Change it from ball_with_radius to your actual variable, radius, and it should work :)
printf("A ball with radius of %f inches.", radius);
Lewis Davidson
694 Pointsprintf("A ball with radius %f. \n", radius); worked the & was causing an error, thank you!
Thomas King
15,197 PointsAh, that must have something to do with Objective-C's syntax, glad my answer could help. I'll update it without the ampersand.