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 (Retired) Fundamentals of C Variables

I cant get past this.

I put in the right code for float but it wont take it.

Stone Preston
Stone Preston
42,016 Points

please post the code you tried to use

11 Answers

Stone Preston
Stone Preston
42,016 Points

remember, creating a float variable looks something like

float myFloat = 1.0;

make sure you didnt make the mistake of using '14.5' for the floats value. A float is a number, it is not enclosed in quotes

float radius = 14.5; printf("%f radius of ball\n", radius);

Stone Preston
Stone Preston
42,016 Points

The challenge states: "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."

you put:

printf("%f radius of ball\n", radius);

which would output 14.5 radius of ball

the challenge needs the output to be A ball with a radius of 14.5 inches So your printf's output is incorrect.

remember that the variables value shows up in the string where you put the format specifier. See if you can figure it out now

OK I will retry it.

I cant get it....

float radius = 14.5; printf("%f ball with a radius of\n", radius);

still didnt work

Stone Preston
Stone Preston
42,016 Points

youve tried

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

remember what I said about the value of the variable being inserted into the string where the format specifier is? with that printf statement, the value of radius is inserted at the front of the string where your %f is. which would outpu 14.5 ball with a radius of which is still incorrect. The format specifier is in the wrong place. that %f needs to be where you want 14.5 to show up.

oh ok, I thought it always had to be in the beginning.

Stone Preston
Stone Preston
42,016 Points

yeah it can go anywhere in the string, as long as its in between the " ".

ok that makes all the difference... thanks...back to the drawing board. this newbie will laugh at this someday.

ya got it!