title: Why doesn't my final scanf stop and read user input?
body: <p>Can anyone tell me why my code works fine until I get to the final scant, where I ask the user if they'd like to play again? For some reason, the program seems to ignore this line of code. Please be gentle as I'm new to programming and trying to teach myself Objective-C. This program is typical for noobs, where I generate a random number, ask the user to guess, then ask if they'd like to play again. Thank you.</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  int main(int argc, const char * argv[])
  {
  
      @autoreleasepool {
  
          int randomNumber = arc4random_uniform(100); // This is a random number generator that gens a num betw 0 and 100
          int userNumber;     // This is the number that the user picks intially
          int attempts = 0;   // This is the number of attempts the user makes during each game
          int games = 0;      // This is the number of games the user has played
          char play = 'n';    // This is whether the user wants to play again, intially set to 'y'
  
          scanf("%c", &amp;play);
          while (play == 'y') {
  
              NSLog(@"Random number is: %d", randomNumber);
              NSLog(@"Enter a number between 0 and 100");
              scanf("%d", &amp;userNumber);
              games++;    // Increment the number of games the user has played to 1
  
              if (userNumber == randomNumber) {
                  attempts++;
                  NSLog(@"Congratulations. You guessed correctly!");
              }
  
              attempts++;
  
              while (userNumber != randomNumber) {
  
                  if (userNumber &lt; randomNumber) {    // Guess is too low
                      attempts++;                     // attempt is incremented
                      NSLog(@"Too low. Try again!");  // User tries again
                      scanf("%d", &amp;userNumber);
                  }
  
                  if (userNumber &gt; randomNumber) {    // Guess is too high
                      attempts++;                     // attempt is incremented
                      NSLog(@"Too high. Try again!"); // User tries again
                      scanf("%d", &amp;userNumber);
                  }
              }
              NSLog(@"Congratulations. You guessed correctly!");
              NSLog(@"It took you %d attempts to guess correctly", attempts);
  
  
              NSLog(@"Do you want to play again?");
              scanf("%c", &amp;play); // --------- Here is where things to wrong ---------
  
          } // while play is yes
  
      } // autoreleasepool
      return 0;
  } // main
  </code></pre>