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

Why is this the wrong format?

Not sure what I am doing wrong here.

variable_assignment.mm
float radius;
radius = 14.5; 
printf("A ball with a radius of %.2f inches.",radius);

2 Answers

You said %.2f in your string. It should just be %f.

You are doing OK in general. %.2f means - two numbers after floating point - 14.50. %.3f - three numbers after floating point - 14.500. and so on %.1 - 14.5.

But I'm not sure what exactly the task is about and why you get some errors.

For the challenge, they just want %f. This is what they're looking for.

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

Thank you for your help I guess what is confusing is

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

outputs to

A ball with a radius of 14.500000255 inches