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