You are using the variable X twice. Once to hold the guess of the user and then a second time to do a loop after the user guesses the right number. This is very sloppy code. You should use Z or something else for the loop variable.