Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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