0

收到“预期表达式”错误但不知道为什么?已对错误消息进行了注释,并省略了 Calculator .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;
}
4

1 回答 1

3

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

于 2013-10-04T16:50:54.300 回答