I want to test how the do-while loop works. But I encounter a problem, which I've spent an hour working on but couldn't figure out a solution. Here's my code.
int main(void)
{
int n;
do
{
// n = get_int("Please type in an integer here: ");
}
while ( n < 0 || n > 23);
{
printf("%i\n", n);
}
}
My aim is to let users type in an integer, and then check if it fits in the rule. If it does, then print it on the screen. But the system constantly reminds me:
mario.c:11:13: error: variable 'n' is uninitialized when used here [-Werror,-Wuninitialized] while ( n < 0 || n > 23); ^ mario.c:6:10: note: initialize the variable 'n' to silence this warning int n; ^ = 0 1 error generated.
It seems to be asking me to initialize the "n" in the while(). But I suppose I've done this in the very beginning. Could you help me find out where goes wrong? :)