0

I really wanted to find or discover the solution for myself, but after many hours I give up. Here is the error message and code, thanks.

mario.c:19:1: error: expected identifier or '('

#include <cs50.h>
#include <stdio.h>

int height;

int main(void)

// Get and print height variable    

{
    do
    {
        height = get_int("Height: ");
    }
    while (height < 1 || height > 8);
}

//Print pyramid
{   
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < i; j++)
        {
            printf ("#");
        }
        printf ("\n");
    }        
} 
2

The problem is that you've ended your program too early. A program has the following structure:

int main(void)
{
    [all of the code goes here]
}

The specific problem is that the closing curly brace for main() is the one following the while statement. At least, that's the way the compiler sees it.

Looking at the code as a whole, it appears that you've put different blocks of code within curly brace pairs, but there's not really a curly brace pair that encapsulates the entire main() program. As written, the two outer curly brace pairs are unnecessary, but there does need to be one cb pair that surrounds all the code.

If this answers your question, please click on the check mark to accept. 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 .