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 trialJames Paulson
105 Pointschallenge task 2 of 2, fundamentals of C. problem with the equation... please help
the challenge task says; "Q: 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 float is: float radius = 14.5 ;
i'm having problems with finding the proper answer. i came up with this;
float A_ball_with_a_radius_of = 14.5 ; printf("%f A ball with a radius of.\n", A_ball_with_a_radius_of) ;
please tell me where i was wrong and what the right answer is. thank you.
James Paulson
3 Answers
Dustin Matlock
33,856 PointsHey James, you should have this so far.
float radius = 14.5f;
printf("%f A ball with a radius of 14.5 inches.\n", radius);
Andrew Thomas
648 PointsGreat. Thank you Jason. The code i was entering and failing with was as yours but with the (...inches.\n", raidus); Maybe that was the reason? I passed the challenge but I just wanted to make sure I wasn't missing something. Thanks again.
Jason Anello
Courses Plus Student 94,610 PointsYou have a typo on radius
Was that in your code too or just that way here?
It could be both the period and the \n
. I never tried that but I think others have passed with just the \n
It may even pass with ...inches
No line return or period at the end.
Andrew Thomas
648 PointsYeah the radius was a typo on here - i checked it a million times on there. As a budding dyslexic you can never be to careful! Thanks for your help though boss. Much appreciated.
James Paulson
105 Pointsdustin matlock, thank you. i have been trying at this for the last two days. you have made it look so simple.
James Paulson
105 PointsJames Paulson
105 Pointsdustin matlock, thank you. i have been trying at this for the last two days. you have made it look so simple.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThis works but I don't see how it is correct. This outputs 14.5 A ball with a radius of 14.5 inches.
I think it should be:
Rather than have the 14.5 hard coded into the output, the challenge wants you to use the variable instead.
Andrew Thomas
648 PointsAndrew Thomas
648 PointsWhy does Dustin's version work. Following the video I would have thought it to be as Jason wrote it:
float radius = 14.5; printf("A ball with a radius of %f inches.", radius);
I tried Jason's version for ages but when i tried Dustin's the code checked out as correct. How come this is the case? Would someone please explain?
Thank you.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Andrew,
I'm not sure if you are saying you could not get the code I posted to pass but it may have been a challenge glitch for you. I just tried again to make sure and it does pass.
As far as why the other one passes, some challenges aren't as rigorous in checking the output and sometimes incorrect answers sneak by.
The challenge does correctly catch this one:
You get an error here about it being the correct string but not the correct format. This produces the correct output but doesn't make use of the radius variable.