Hello I'm trying to write a simple number guessing game in c. If the player guesses the number correctly, the program will give a message and aks if the player want to play again.
When i compile the code, it generate the random number, let the player guess the number and check whether the number is right or not. But when it aks if the player want to play again, it does not let the player answer and instead just exit. I don not know why it happens. Can you please help me?
int main()
{
int number, guess_value,number_of_guesses;
char answer;
srand((unsigned)time(NULL));
number=rand() %100+1;
A:number_of_guesses=0;
while (guess_value != number){
printf("\nEnter a number between 0 and 100\n");
scanf("%d", &guess_value);
number_of_guesses++;
if (guess_value == number){
printf("Right !!! You win\n");
}
else if (guess_value > number){
printf("\nYour guess is too high. Guess again");
}
else {printf("\nYour guess is too low. Guess again");
}
}
printf("You guessed %d times !", number_of_guesses);
printf("Do you want to play again? y? n?");
scanf("%c", &answer);
if (answer == 'y'){
goto A; /*return to to beginging*/
}
return 0;
}