1

Here is my code:

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

int main(void)
{
    int n;
    do
    {
        printf("height: ");
        n = get_int(" ");
    }

    while
    {
       (n < 1 || n > 8);
    }

}

Here is the error I get:

$ make mario
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    mario.c  -lcrypt -lcs50 -lm -o mario
mario.c:14:5: error: expected '(' after 'do/while'
    {
    ^
1 error generated.
<builtin>: recipe for target 'mario' failed
make: *** [mario] Error 1

I have searched for a while now but can't find out where/why the '(' is expected besides where I already have it. Any help will be greatly appreciated.

1

You should write

do {
     printf("height: ");
     n = get_int(" ");
} while (n < 1 || n > 8);

instead of

do {
    printf("height: ");
    n = get_int(" ");
} while { 
    (n < 1 || n > 8); 
}

In the do...while loop, the condition is at the bottom of the loop, in parentheses.

You must log in to answer this question.

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