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 Object-Oriented Objective-C Diving Deeper - Classes, Properties and Methods Creating Methods!

Method does not work

Why?

variable_assignment.mm
-(float*)calculateTip:(subtotal*)subtotal {
 subtotal *= 0.2; 
}

1 Answer

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

You have a few issues with your code.

Firstly, subtotal is of type float, so you should have "float" in the parentheses in front of "subtotal" rather than "subtotal" in the parentheses.

Secondly, floats are primitive types, which means they don't need the * immediately after them. You should get rid of those *.

And finally, you need to return subtotal * .2, not just multiply subtotal by .2 and store it back in subtotal.

-(float*)calculateTip:(subtotal*)subtotal { // CHANGE (float*) TO (float) AND (subtotal*) TO (float)
 subtotal *= 0.2;  // REPLACE THIS LINE WITH return subtotal * .2;
}

I hope this helps!