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

challenge 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

Hey James, you should have this so far.

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

dustin matlock, thank you. i have been trying at this for the last two days. you have made it look so simple.

This 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:

float radius = 14.5;
printf("A ball with a radius of %f inches.", radius);

Rather than have the 14.5 hard coded into the output, the challenge wants you to use the variable instead.

Andrew Thomas
Andrew Thomas
648 Points

Why 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.

Hi 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:

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

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.

Andrew Thomas
Andrew Thomas
648 Points

Great. 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.

You 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
Andrew Thomas
648 Points

Yeah 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.

dustin matlock, thank you. i have been trying at this for the last two days. you have made it look so simple.