c - The while loop wont loop and the program ends on the last printf statement...any ideas why? -


while(play == 'y' || play == 'y') {                         {                     printf("max number of guesses %d\n", count);                     printf("what guess? must between 1 , %d\n", $                     scanf("%d", &guess);                      if(guess > randnum)                     {                             printf("too large!\n");                             count = count -1;                     }                     else if(guess < randnum)                     {                             printf("too small!\n");                             count = count -1;                     }                     else                     {                             printf("%s, guessed number!\n", name);                             yournum = guess;                     }             } while(yournum != guess || count == 0);              printf("play again? (y/n)\n");             scanf("%c", &play); 

i think need 'do while' first while loop user able play once .my assumption play variable not initialized 'y' or 'y' that's why while loop not getting executed.more code required . suggestion this`

            do{             {                     printf("max number of guesses %d\n", count);                     printf("what guess? must between 1 , %d\n", $                     scanf("%d", &guess);                      if(guess > randnum)                     {                             printf("too large!\n");                             count = count -1;                     }                     else if(guess < randnum)                     {                             printf("too small!\n");                             count = count -1;                     }                     else                     {                             printf("%s, guessed number!\n", name);                             yournum = guess;                     }             } while(yournum != guess || count == 0);              printf("play again? (y/n)\n");             scanf("%c", &play);  }while(play == 'y' || play == 'y') 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -