the first time around, the program works as expected. the integer x is set to 0 when a response is given other than 'y,Y,n,or N' so that the function will repeat. the second time around, even if 'y,Y,n,or N' is given as the reponse, the program seems to think that answer contains something else...perhaps the previous input? do i need to initialize answer each time around? thanks for the help if u can..extremely new here
Code:void playgame() { char answer; int x = 0; while ( x == 0){ printf( "Maybe we can play a guessing game instead? Y or N\n"); getchar(); scanf( "%c", &answer ); if ( (answer == 121) || (answer == 89) ) { printf( "Ok, but you will surely give up before you win!\n" ); x = 1; } else if ( (answer == 110) || (answer == 78) ) { printf( "Well then, go find someone else with whom to play.\n" ); x = 1; } else { printf( "That was an invalid answer. Please concentrate and try again.\n" ); x = 0; getchar(); } } }