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.

iOS Objective-C Basics Basic Data Types and Variables Numerical Variables

float foodPrice; foodPrice=3.50; what is wrong???

what is wrong in this?

variable_assignment.mm
float foodPrice;
foodPrice=3.50;
Antonio Montalvo
Antonio Montalvo
10,549 Points

Hi Marco, You should declare first a variable and give it a name. Then you can specify that the variable is of the type Float, and then give it a value. After the variable has been declared then toy can modify it's value. I hope this works for you.

var foodPrice: Float = 3.50; foodPrice = 2.6;

Chris Shaw
Chris Shaw
26,650 Points

Hi Antonio Montalvo,

The example code you have given is Swift whereas Marco is working with Objective-C.

1 Answer

Chris Shaw
Chris Shaw
26,650 Points

Hi Marco,

I assume you have removed the code for the first task which is required for task 2 to pass, along with that you simply need to assign your float value as you did in task 1. See the following:

int size = 13;
float foodPrice = 3.50;

You were essentially correct aside from those two things.

Happy coding!

Antonio Montalvo
Antonio Montalvo
10,549 Points

Sorry Marco, I didn't realize it was Objective-C.