one of the necessary work is to implement the "sin" button on the calculator. Add the following 4 control buttons: β’ sin: calculates the sine of the top operand on the stack.
here is my code
- (double)performOperation:(NSString *)operation { double result = 0; if ([operation isEqualToString:@"+"]) { result = [self popOperand] + [self popOperand]; }else if ([@"*" isEqualToString:operation]) { result = [self popOperand] * [self popOperand]; }else if ([operation isEqualToString:@"-"]) { double subtrahend = [self popOperand]; result = [self popOperand] - subtrahend; }else if ([operation isEqualToString:@"/"]) { double divisor = [self popOperand]; if(divisor) result = [self popOperand] / divisor; }else if([operation isEqualToString:@"sin"]){ double operd = [self popOperand]; NSLog(@"operd=%g",operd); if(operd) result = sin(operd); } [self pushOperand:result]; return result; }
I am trying to enter sin (60) and the result = -0.304811
but in fact I use a calculator in Windows and the result is 0.8860254
I do not know what is wrong with my code
source share