How to solve error: expected identifier or ‘(‘

You got nested loop with do/while. Make sure that each start with do end with while.

Look like at the end of file, the “while” is not correct.

printf("\n");
rows++;

while (rows <= height);
}

That could be you missing the close ‘}’ before ‘while (rows <= height);’

Correct code could be:

int main(void)
{

    //Ask User for Height, and check

    int a, b, rows, height;
    a = 0;                    // <- removed int
    b = 0;                    // <- removed int
    rows = 1;                 // <- removed int

    do
    { 
        printf ("Height: ");
        height = GetInt();
    }
    while (height <=0 || height > 23);   

    //build half pyramid

    do
    {
        do
        {
            printf("r");
            a++;
        }
        while (a < height - rows);

        do
        {
            printf("#");
            b++;
        }
        while (b < rows + 1);

Leave a Comment