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