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

Trouble with Variables Code Challenge

When i do the variables code challenge on objective-C the 2nd task i do it correct but it says its not in the correct format??!! Help!!

Can you link the code challenge and tell us what you have tried that didn't work?

http://teamtreehouse.com/library/variables-2

Thats the link but when i do it its all right but it says "its in the wrong format"

Ugh... My account is having issues accessing code challenges, can you please include the follow two items:

  1. The problem statement in the code challenge. What is it asking you?
  2. Your rejected solution(s). What have you tried?

Without either, it is impossible for me to guide you in the proper direction.

well the first task it says to type a float named "radius" with the value of 14.5,,,, I got that one right my response was float radius = 14.5;

The 2nd task was create a print statement and the output being " A ball with a radius of 14.5 inches" but when i try it says "its in the wrong format" and my response is...

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

help!

6 Answers

well the first task it says to type a float named "radius" with the value of 14.5,,,, I got that one right my response was float radius = 14.5;

The 2nd task was create a print statement and the output being " A ball with a radius of 14.5 inches" but when i try it says "its in the wrong format" and my response is...

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

help!

:) Now it is very clear what's wrong! If you follow this same format each time you ask a question, you can get answers much quicker!

printf replaces occurrences of %f, %d, %c, %s, %@, etc. (you get the idea) with the value of what follows the comma, hence, what you have there would produce this instead:

14.5 A ball with a radius of 14.5 inches.

Give it some thought, let it sinks in first. How would you make the number in A ball with a radius of 14.5 inches be dynamically replaced with the value of radius?

thanks you helped me a ton!!!

you answer is still not helping!! can you just give me the answer

It would be harmful if I have just given you the answer right away, there are many things to learn beyond this and most of the time you just have to figure it out as much as you can yourself. But here's something to get you closer:

You want to print out something like A ball with a radius of ??? inches, where ??? is the value of your variable radius, now use %f instead so ??? gets replaced by the proper value from radius. Your answer should look something like this:

printf("A ball with a radius of ....", radius);

If this is still not enough, you may want to watch the video again.

Thanks now you helped it worked.. Thanks!!!

When I put this-- printf("A ball with a radius of %f inches.\n", radius); It rejects it. HELP

DON'T put inches after %f

Thanks

Glad it helped!

Rejected the function again. Sorry. float radius = 14.5; printf("A ball with a radius of %f.\n", radius);

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

Well not on the computer right now ask again tommorrow and I'll be glad to help!!

If the help is still offered, I would be grateful to get it. Thanks.

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

Thank you so much!!

your very welcome!!

Ans, Float radius = 14.5; Printf("%f radius.\n", radius); printf("A ball with a radius %f\n", radius); printf("A ball with a radius %f\n", radius);