2013-02-11 27 views
-3

正如標題所示,我收到此編譯器錯誤「使用未聲明的標識符」。我試圖給「結果」寫一個「operationPerformed」,它基本上是一些數學方程式。我是Xcode的新手,所以不要懲罰我:)。感謝你的時間!iOS:在簡單計算器中使用未聲明的標識符錯誤

代碼編輯相應

@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]]; 
} 
+1

請顯示*確切*錯誤消息。在這種情況下,它確切地告訴你問題是什麼。 – 2013-02-11 22:45:52

+2

好的,我解釋一下*** ***最後***時間:它不是Xcode,錯誤,它是編譯器,而且從不知道有多少人被濫用,並會濫用那個可憐的「xcode」標籤,它會保持原樣, IDE,它不會神奇地成爲編譯器。 – 2013-02-11 22:46:58

+1

知道確切的消息,以及它標記的線會非常有幫助。 – 2013-02-11 22:48:21

回答

1

這條線:

double result = performOperation:operation; 

是無效的語法。也許你想要:

double result = [self performOperation:operation]; 

沒有更多的上下文,很難說。

+0

是的,可能就是這樣。或者至少有一個。 – 2013-02-11 22:49:10

+0

我已經更新了代碼,並在這種情況下得到了另一個錯誤 – 2013-02-11 22:54:23

+0

您還有一個類似的東西:'setOperand:[[display text] doubleValue];'我認爲你應該得到一本初學者書。 – 2013-02-11 23:01:57

相關問題