0

My Do While Loop isn't working for some reason, the error is outlined below. Can anyone help me figure this out (I included the stdio and cs50 libraries)?

int main(void);

int n;
{ // error: expected identifier of '('
    do
    {
        printf("Height of pyramid:");
        n = GetInt();
    }
    while (n >= 1 && n <= 23);
    return n;
}
1

Simple problem. You put a semicolon in int main(void); The correct structure is:

int main(void)
{
    // code goes between curly braces
}

You also have a declaration statement, int n; before the first brace.

The compiler assumes you mostly know what you are doing, so the two lines with main and int n which end in semicolons look like a function signature declaration and a global variable declaration to the compiler. (It assumes you know how to start main().) The first thing that looks out of place to the compiler (because of that semicolon) is the first curly brace.

You would benefit greatly from a review of how to structure a program.

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

| improve this answer | |
  • Interestingly enough, the compiler told me to put the semicolon after (void) through an error message, but once I declared int n within the brackets, it stopped doing so ¯_(ツ)_/¯ – K. Roe Sep 22 '15 at 3:23
  • Because the compiler thought you were making a "function signature declaration" (prototype as it's called in lecture), as Cliff mentioned. Prototypes do need a semicolon. Nice ASCII art! – Sam Gerber Sep 22 '15 at 5:58

You must log in to answer this question.

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