So, I've been working on mario for some time, and I've pasted the code I've made, which is faulty but I have not idea how to fix it. The program is telling me that for the line "for (int i = 0; i < n; i++)", there needs to be an expected identifier or '(' before/near the "for". However, the second error states that there is an expected ')' at that same exact spot...

int main(void)
    printf("Your number, between 0 and 23");
    int n = 0; n = GetInt();
    for (int i = 0; i < n; i++)
        for (int a = 0; a < (n - (i+1)); a++)
            printf(" ");

        for (int b = 0; b <= (i + 1); b++)

Could you please help me figure out what I'm doing wrong? Thanks so much!!!

1 Answer 1


The problem is that you have placed your curly braces in the wrong place. It's a common error for new programmers. Learn to recognize this error. In the beginning, it will most often mean a problem with parentheses or curly braces.

Very simply, the closing curly brace for main() occurs before the for loop that is pointed out in the error. The compiler thinks that you have closed main() and it is expecting proper formatting for a new function, a declaration statement, or something else appropriate at that point.

This also demonstrates how one error can cause a whole series of other errors and it is necessary to fix them in order. (For instance, a single undeclared variable will appear as an error at every point that the variable appears. If you used it in 20 places, the one fix of adding the declaration statement would fix all 20 errors at once.)

Reformatting your code more carefully, as I have done above, might have shown you what had happened. You should get more familiar with the style50 program and occasionally run your code through it to see what it says about your code formatting. You'll develop better habits by doing so and following it's advice.

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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