0

I've had this problem since the beginning. I got error messages saying it expected a semicolon after int main (void), and this one has been persistent. It tells me it expects an identifier '(' instead of a '{' . I have tried moving the curly braces all over to see if I could fix it, I have looked all over the internet and still can't figure it out.The problem was there even when I only had my do-while loop. Can anyone help?

#include <cs50.h>
#include <stdio.h>
int main (void);
int n;
int s;
int ttl;
int hshtg;

{  \\this is where the error is\\
printf("Height: ");
do{
    int n = get_int;
}while(n < 0 && n > 23);

int s = n - 1;
int ttl = n + 1;
int hshtg = ttl - s;

for (int i = 0; i < n; i++)
{
    printf("%i",' '*s)
    printf("%c",#*hshtg)
    printf("\n")
}
}
1

The body of the main function must go in parentheses, and without semicolon, and without declaring anything before the first parenthesis, but the compiler thinks that you are defining a function (hence the warning of the semicolon) the correct form would be

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

    int main (void)  
    { 
        int n;
        int s;
        int ttl;
        int hshtg;
        printf("Height: ");

        do{
        .....
    }
2
  • Thank you very much MARS. If you could help me with one more thing, now it tells me this: error: declaration shadows a local variable [-Werror,-Wshadow] int n = get_int previous declaration is here int n; It does it with the other variables too. – Laura Hernandez Apr 23 '17 at 23:03
  • If you look, you declare twice int n, if you do this within a loop you actually do declare a new variable, with the same name. Of there the error, every time you use the variable you should not always do int n, simply n = get_int() , whith parenthesis – MARS Apr 23 '17 at 23:18
1

Remove the semi-colon of the main function:

int main (void)
{
    // Functions do not require a semicolon


}

That's not the only error your code has.

Also comments are done with Fore-slashes (//) not Back-slashes (\)

Other errors your code has:

do{
    int n = get_int(); // You're missing the parentheses () when calling function get_int()
}while(n < 0 || n > 23); // Use or (||) instead of and (&&) 

You must log in to answer this question.

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