0

I have been working on cs50 problem set 2 and I have come across the error

readability.c:35:1: error: expected expression
else if( index > 16)
^

My code is as follows

 if(index < 1)
    {
        printf("Before Grade 1");
    else if (index > 16)
    {
        printf("Grade 16+");
    }
    else
    {
    printf("Grade %i", (int)index);
    }
    }
0

Simple. The code is missing a closing curly brace before the else if statement.

Without it, the compiler doesn't understand which if statement it should be paired with, or if the elseif statement is supposed to be inside the code block for the if statement, in which case there would be a missing if statement.

Actually, it looks like the missing closing curly brace is at the end of that code and needs to be moved. (If you insert a closing curly brace instead of moving the last one, it will generate a different error because that last curly brace couldn't be paired with an opening curly brace.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .