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

General Discussion

Question for fundamentals of objective c with a code challenge.

question is... 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.

my answer is... float radius = 14.5; printf("A ball with a radius of 14.5 inches %f\n");

I have no idea. Any help would do. Thanks

3 Answers

Format specifiers are meant to make the string more dynamic. What you have is an error. The point of using format specifiers (%f, %d, etc.) is so that you may update the value in the string, if it's ever to change.

  1. 14.5 should be replaced with %f
  2. You didn't pass your variable to printf as an argument, so no value is being supplied where %f is
float price = 20.99;
printf("My meal came out to be %f dollars.", price);

Let's say the cashier decides to give me a 20% discount.

float price = 20.99
float discount = .20 * price;
price -= discount;
printf("My meal came out to be %f dollars.", price);

My value updates without the need to statically type the new price in.

Also, this is an Obj-C question, not General Discussion.

It helped thanks!

include <stdio.h>

int main () { float radius = 14.5; printf("A ball with a radius of %f inches.", radius);

return 0; }

I don't know what's wrong with this answer, it just not right..