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!