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

Help with Variable Assignment

Im in the Variable assignment and Im having no problem putting float radius = 14.5 the problem Im having is setting the printf in task two, I have tried everything and Im coming empty handed.

Is saying to set radius with a printf to output: A ball with a radius of 14.5

Im putting

float radius = 14.5;

printf("%f a ball with a radius"); return 0; I also tried moving things around but no luck have been on this for the past 45 minutes, so a little help would help guys, thanks in advanced.

5 Answers

Hi Alexander you need to put the variable in at the end of the printf statement like in the example below. You can see that the printf begins with the token place holder such as %d %f %c etc then the string statement followed by the variable. Remember when you output a value from a variable in a printf statement you need to put the variable in it to, as the value held in the variable will be substituted for the token place holder.

So to run through an example

int days_in_a_week =7;

//Here you set the return type of a value (int) the name of the variable (days_in_a_week) and then set it equal to 7.

printf("%d days in a week\n", days_in_a_week);

//To output this you put in %d as the place holder as it int value you are returning, then the string you need to output "days in a week", finally followed by the variable which you declared in this case days_in_a_week.

So your output would be printf("A ball with a radius of %f inches",radius);

Hope this helps

I just did the code challenge again this worked for me, give it a shot and see what happens as I say it worked just now....

printf("A ball with a radius of %f inches",radius);

Im saddened to say that even though I understand much better with your example, still no luck or results, I have gone to the video about 6 times now, I have even tried on my Xcode a million different ways, I have modified and modified in different versions to see if I can pass this challenge or even get an output on Xcode and nothing has resulted correctly. I cannot get the right output on the challenge or in Xcode. Im not sure what Im doing wrong. And what sad is Im only starting in this course and Im already stuck for hours.

Oh my gosh, finally, now Im going to be testing this on my Xcode too, make sure it works, I have no ida what I was missing, one thing is for sure I have all those codes burnt into my memory for the rest of my life no doubt. Hey thanks a million Sam.

No problem glad to have helped. Hope you enjoy the rest of the course, think by the time you get to the end it will all come together.