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 Code Challenge Issue

Hey guys

I've started doing the new Object-C basics series with Doug Turner and I've been stuck on the final part of the code challenge for Fundamentals of C - Variables I've added the two variables correctly in parts 1 & 2, but part 3 I'm stuck on. I've declared everything in what I think is correct as I have tested it out in Xcode with no problems.

Here is the question: Add a printf statement to print both variables. Here is what your output should look like: 6 balls each with a radius of 14.5 inches.

Here is the source in the final part of the question.

float radius = 14.5;
int count = 6;

printf ("%d balls each with a radius of ", balls);
printf ("%f inches", radius);

Here is the error that I get Make sure you are passing a string instead of a NSString to printf. Also, make sure you have the correct format options. %d is used for integers and %f is used for floats.

I just don't know what to make of this. Am I to do this in Object-C or in C?

Any help will be greatly appreciated, and I'll keep racking my brains to try and find the answer.

Thanks in advanced

Stu :)

7 Answers

Looks like you're printing those statements on two separate lines. They're asking for a single print statement. Just try fitting what you have in the second line of code into the first line of code and it should pass.

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

I have simplified the challenge given that the preceding video only shows you how to print one variable at a time.

Thanks for the suggestion Stephen though that didn't work for me?! PLZ HELP!

Im adding the printf() statement in task 2 for this challenge and Im not sure why this is not passing: float radius = 14.5; printf("%f A ball with a radius of 14.5 inches.\n", radius);

You want the output to be "A ball with a radius of 14.5 inches.", but what you have right now will output "14.5 A ball with a radius of 14.5 inches." Remember, printf substitutes %f (or other %?) with the variable that follows the string after the comma.

Amit Bijlani, another issue with Obj-C code challenges. Stage 6 Memory Management task 1/3 asks for id something but the code validator wants id thing.

I'm finding the all the quiz challenges that make us fill in the blanks with the code are way too confusing, there has been times where I just sit there scratching my head and, these should be code challenges. I'm really enjoying C but I find I'm losing motivation to do it.

Hey Amit,

So I re-tried the quizzes after taking a days break from Treehouse and referring back to my notes and it makes a lot more sense now.

I think 9 hours straight 6 days in a row was over working my brain.

Stu :)