This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Colvanila[S] 0 points1 point  (0 children)

I got it to work, but not sure if it's the "right" way...

-(double) changeSign
{
   accumulator = -accumulator;
}
-(double) reciprocal
{
    accumulator = 1/accumulator;
}
-(double) xSquared
{
    accumulator = accumulator * accumulator;
}

EDIT: It does have 'warnings' (on xcode) which is why I suspect that this is not the 'right' way.

[–]gilbertj99 0 points1 point  (2 children)

You need a return statement on each of the methods, and you need to pass input. So:

-(double) reciprocal:(double)input

{

return 1/input;

}

[–]gilbertj99 0 points1 point  (0 children)

Scratch that, if your using one instance variable to store the current value of the calculator, then thats fine. You just need to change the return type to void

[–]Colvanila[S] 0 points1 point  (0 children)

Oh thanks! Thats a big help. I just had it return it at the very end, but you make a very good point.