-3

正如标题所说,我收到了这个编译器错误“使用未声明的标识符”。我正在尝试将“结果”写入“操作执行”,这基本上是一些数学方程式。我是 Xcode 的新手,所以不要惩罚我:)。感谢您的时间!

相应编辑的代码

@interface CalculatorViewController ()

@end

@implementation CalculatorViewController
-(void)setOperand:(double)aDouble
{
    operand = aDouble;
}

-(double)performOperation:(NSString *)operation
{
    if ([operation isEqualToString:@"sqrt"])
    {
        operand = sqrt(operand);
    }
    else if ([operation isEqualToString:@"+/-"] && operand !=0)
    {
        operand = -1 * operand;
    }
    else if ([operation isEqualToString:@"1/x"] && operand !=0)
    {
        operand = 1.0 / operand;
    }

    else if ([operation isEqualToString:@"sin"])
    {
        operand = sin(operand);
    }
    else if ([operation isEqualToString:@"cos"])
    {
        operand = cos(operand);
    }
    else if ([operation isEqualToString:@"tan"])
    {
        operand = tan(operand);
    }
    else
    {
        [self performWaitingOperation];
        waitingOperation = operation;
        waitingOperand = operand;
    }
    return operand;
}

-(void)performWaitingOperation
{
    if ([@"+" isEqual:waitingOperation] )
    {
        operand = waitingOperand + operand;
    }
    else if ([@"*" isEqual:waitingOperation])
    {
        operand = waitingOperand * operand;
    }
    else if ([@"-" isEqual:waitingOperation])
    {
        operand = waitingOperand - operand;
    }
    else if ([@"/" isEqual:waitingOperation])
    {
        if(operand)
        {
            operand = waitingOperand / operand;
        }
    }
}

-(IBAction)operationPressed:(UIButton *)sender
{
    if (userIsInTheMiddleOfTypingANumber)
    {
        setOperand:[[display text] doubleValue];
        userIsInTheMiddleOfTypingANumber = NO;
        decimalAlreadyEnteredInDisplay = NO;
    }
    NSString * operation = [[sender titleLabel] text];
    double result = [self operformOperation:operation];
    [display setText:[NSString stringWithFormat:@"%f", result]];
}
4

1 回答 1

1

This line:

double result = performOperation:operation;

is invalid syntax. Maybe you wanted:

double result = [self performOperation:operation];

Without more context it's hard to say.

于 2013-02-11T22:47:50.677 回答