获得预期的表达错误

时间:2013-10-04 16:47:54

标签: objective-c

我得到了“表达预期”错误,但无法弄清楚原因?已注释错误消息,并省略了计算器.h,.m文件。

#import <Foundation/Foundation.h>
#import "Calculator.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        double value1, value2;
        char operator;
        Calculator *deskCalc = [[Calculator alloc]init];

        NSLog(@"Type in your expression.");
        scanf("%lf %c %lf", &value1, &operator, &value2);

        [deskCalc setAccumulator:value1];
        if (operator == '+') {
            [deskCalc add: value2];
            else if (operator == '-') // Expected expression
            [deskCalc substract:value2];
            else if (operator == '*') // Expected expression
                [deskCalc multiply:value2];
            else if (operator == '/') // Expected expression
                [deskCalc divide:value2];

            NSLog(@"%.2f", [deskCalc accumulator]);
        }



    }
    return 0;
}

1 个答案:

答案 0 :(得分:3)

您将else if条件放在与原始if相同的表达式块中。您需要移除if (operator == '+')块周围的大括号。