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
Post a Comment