iOS Object-Oriented Objective-C Diving Deeper - Classes, Properties and Methods Creating Methods!

surya m
surya m
542 Points

what's wrong in my code?

Create a method called 'calculateTip' that takes a float variable called 'subtotal' as a parameter, multiplies that value times 0.2 and returns a float value.

variable_assignment.mm
-(void)calculateTip = (subtotal*0.2);

1 Answer

Antoine Barthelet
Antoine Barthelet
3,738 Points

functions in objective C follow a format: -(return type of function) function name: (input 1 type) Input_1_name andInput_2_name:(input 2 type) Input_2_name{ function code }

So in your case, the answer would be: -(float) calculateTip: (float) subtotal{return subtotal*0.2;}

surya m
surya m
542 Points

Thank you Antoine!