Hi there.
I'm in the process of learning C.
I found a good tutorial (though I'm beginning to doubt that now...).
So now there's a problem I'm having trouble with solving.
The following is a sample of a loop with the condition before the code block.
Now, say I input '4'.Code:#include <stdio.h> int main() { const int MAGIC_NUMBER = 6; int guessed_number; printf("Try to guess what number I'm thinking of\n"); printf("HINT: It's a number between 1 and 10\n\n"); printf("debug: guessed number = %d", guessed_number); printf("Enter your guess: "); scanf("%d", &guessed_number); while (guessed_number != MAGIC_NUMBER); { printf("Enter your guess: "); scanf("%d", &guessed_number); } printf("\n\nYou win!\n"); return 0; }
It should enter the loop if I'm not mistaken.
But apparently I am mistaken, because when I compile it and I enter '4' it doesn't do anything.
It doesn't even print the debug line.
So what's the catch?
Is my compiler nuts or is there something wrong in the code?
Thanks.




Reply With Quote