0

I have been trying for more than a week to correct compiling error: mario.c:19:1: error: expected identifier or '('

The response I received did not help.

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

int main(void)

{
int height;

do
    {
    printf("Enter a positive intiger less than 24\n ");
    height = GetInt();
    }

while (height < 1 && height > 23);

// The opening curly bracket below this line (c19) is the one referred to in the compiling error message

{
int line;
for (line = 0; line < height; line++)

    // print spaces

    int space;
    int x = (height - line); 
    {
    for (space = 0; space < x; space++)
    printf(" ");
    } 

   // print hashes

    int hash;
    {
        for (hash = 0; hash < (line + 1); hash++)
        printf("#");
    }
        // print new line
    printf("/n");
}

4 Answers 4

0

You are not supposed to put semi-colon after the for loop statement. Go through the syntax of the for loop again.

0

You should enclose for loop statements inside braces {}. Syntax of for loop:-

for ( init; condition; increment ) {
     statement(s);
}
0

That curly brace should go after the for statement, not before.

0

HERE IS MY CODE CHECK IT OUT FOR HELP.......THANKS :)

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

int get_positive_int(string prompt);

int main(void)



{

 int height = get_positive_int("Height: ");
     for ( int row = 1 ; row <= height ; row++ )
    {

        for ( int column = 1 ; column <= height ; column++ )
        {

            if ( column >= height + 1 - row )
            {
                printf("#");
            }
            else
            {
                printf(" ");
            }         
        }

        printf("\n");
    }

}

 int get_positive_int(string prompt)
{



    int a;
    do
    {
        a = get_int("%s" , prompt);
     }  

        while(1 > a || a > 8);
        return a;

    }

You must log in to answer this question.

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