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


What step am I skipping in the variables challenge?

What steps am I missing? Why aren't these steps included?

My line of code:

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

2 Answers

Cody Girdlestone
Cody Girdlestone
4,358 Points

You are comparing the challenge too literal to the video. In his video he is saying
the_w = "w";
which means he has created a variable called the_w with the value of w if you typed
the_w = "x";
if you typed
print_f ("The variable the_w is %c", the_w);
you would get "The variable the_w is x";

In the video look at his line that says
printf("%f cm per in.\n", cm_to_in);
as this is effectively all the line required from you is. You just need to replace the variable (cm_to_in) with the new variable (radius) and obviously change the text to print.

Also from looking at the code you have written a few tips
printf("your text block\n",variable);
You need to have the text to print inside the symbol " and it is \n for new line not n\

If you are struggling with the videos make sure you aren't distracted while watching them, concentrate and if need be rewatch them. Treehouse is an excellent resource so make the most of it and it's not a race to finish everything.

Also sorry for the long post but I wanted to help you get the answer, not give it to you as you won't learn from it.

Thank you. I am going back and forth replicating what's on the vid to my xcode project. This is very helpful as I learn better by example. I do appreciate your long answer, I may require more long ones in the future, fyi...

Cody Girdlestone
Cody Girdlestone
4,358 Points

No problem. Best of luck with it all :)

Cody Girdlestone
Cody Girdlestone
4,358 Points

The first step of the challenge asks for you to create a float called radius with a value of 14.5 inches. The next step will continue to use that code from step one and get you to print it.

You don't appear to have step 1 in your code and you also have the wrong variable name in part 2 (ball_with_a_radius should just be radius)

Yes, I got that first line, I didn't include it in this enquiry. What I am asking is this: it's a bit of a jump to get from the float to the printf line. I'm overall perplexed as to how we tie in the radius to "a ball with a radius of". Do I have to include the 'char' part first in order to make the project say what it's supposed to say? I also don't understand why the_w is important? Why is the letter 'w' important? Could one pick any letter in the char part? My second line of code, in my second try is "printf(%f radius.n\,radius)" The area pointed out as being wrong is %f ('two errors generated'). I rewrote it as "printf(radius %f.n\,radius)" and 'one error' was 'generated' at the '%f'. And where does the text come in? Where does one write the text? My instinct tells me it's a simple step, but I don't know which direction to step to. Thanks in advance.