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

int main(void)

int h;
{
do
{  
    printf("Height: ");
    int h = GetInt();
}
while (h < 1 || h > 23);
}

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow mario.c -lcs50 -lm -o mario mario.c:7:1: error: expected identifier or '(' { ^ 1 error generated.

error: expected ';' after top level declarator int main(void)

                                             ^
                                             ;

This error appears when I attempt to run it. I know there isn't suppose to be a semicolon after int main(void), but when it wasn't there it prompted me to add one. I have looked at similar posts and tried to use the solutions that were given to them but it did not work. If anyone can help me it would be very much appreciated. Thank you in advance!

`**}

  • This does not look like it is all of your code. You need to post all of it because it looks like you do not have a '}'to at the end of main to close its scope. Errors with parentheses, brackets, and semicolons are why I have seen this error before. – Brendan Rafferty Jun 7 '16 at 21:07
  • Yes it wasn't all of it. When I copied it I forgot to include the '}'. I also deleted the semicolon after int main(), and another error occured – Nathaniel Islas Jun 7 '16 at 22:50
2

Simply put, you're missing a pair of curly braces. The correct form of main() is this:

int main(void)
{
    // all of the program code for main goes between these curly braces.
}

The curly braces set the beginning and end of main().

At this level, the compiler assumes that you know the basic form and is assuming the problem is something more complex when it isn't. The compiler thinks that the main() declaration is a function signature, not the actual amin() program, and is looking for a semicolon to close the signature (something you'll learn about later.)

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

| improve this answer | |
  • When I copied it I forgot to include the '}'. I also deleted the semicolon after int main(), and another error occured – Nathaniel Islas Jun 7 '16 at 22:52
  • You're still missing the opening curly brace between int main(void) and int h;. The originally posted code would have also worked if you simply moved the opening curly brace after int h; to before it. In any case, you need to make sure they are in the correct location and correctly paired. – Cliff B Jun 7 '16 at 22:57
  • Thank you! It took me a while but I finally got it. – Nathaniel Islas Jun 8 '16 at 0:10

You must log in to answer this question.

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