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

Complete beginner seeking help!

Hello!

I'm new to this and am starting the iOs track. I'm already stuck on the second quiz challenge:

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.

Could someone please help me! Thanks so much!

4 Answers

To do this, you need to understand how the printf statement works. Wikipedia (http://en.wikipedia.org/wiki/Printf_format_string#1970s:_C.2C_Lisp) has a good article on it -- check out the section for C. Basically printf means "print with format", allowing you to format the output using special syntax, like %c for character, %d for integer, and %f for float (or decimal).

Consider the following example:

printf("Color %s, number1 %d, number2 %05d, hex %#x, float %5.2f, unsigned value %u.\n", "red", 123456, 89, 255, 3.14159, 250);

This will output the following: Color red, number1 123456, number2 00089, hex 0xff, float 3.14, unsigned value 250.

So you'll see that each variable or value that is placed in the 2nd and following parameters of the printf function will replace the corresponding control parameter in order of appearance in the main string.

In your case you have the foliowing string: "A ball with a radius of 14.5 inches." You want to use a control parameter instead of the 14.5, so your string would now look like "A ball with a radius of %f inches." You also know how you need to format the printf statement: ```printf("string with control parameter(s)", value(s));

If you put all that together, how would you write the printf statement?

Wow, sorry, but that was way over my head. Thank you anyway, Mike. Should I go learn C?

No need, Kuan! :) You are already learning C with the iOS track. The programming language that iOS is build on is Objective-C, which is an evolution of the original C language. The first part of the course is a primer in the C language.

However, if you don't understand what is being asked of you in the challenge, I would re-watch the video, and take notes as to how they show it being done in the video. Then you can apply that same logic - even if you don't quite understand it just yet. Hopefully, as the course progresses, you will understand the concepts.

Do you have any experience in C++-syntaxed languages, like PHP, C++, etc.? They all have similar syntax and follow similar rules. (C++ is a different evolution of the original C language from Object-C).

I'm as beginner as it gets, Mike! I suspect I'll re-watch that video many times over!

Hi Kuan, I struggled to answer this question. I even asked some full-time iOS devs and they couldn't help me arrive to the answer. I emailed support@treehouse. Do you know how to arrive at the correct answer?