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

Method does not work


-(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!