pdenlinger
pdenlinger

Reputation: 3917

Getting expected expression error

Am getting an "expression expected" error but can't figure out why? Have commented the error messages, and left out the Calculator .h, .m file.

#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;
}

Upvotes: 0

Views: 1778

Answers (1)

RyanR
RyanR

Reputation: 7758

You are putting the else if conditions inside the same expression block as the original if. You need to remove the curly brace around your if (operator == '+') block.

Upvotes: 3

Related Questions