c - My while loop with char doesnt work. Some help please -


so have peace of code:

int choice_dig; char choice_dup; printf("welcome mystery number game.\n"); printf("how many digits want use (3 5)?"); scanf("%d", &choice_dig); while (choice_dig<3 || choice_dig>5) {     printf("\nplease choose number between 3 , 5.\t");     scanf("%d",&choice_dig); } printf("\ndo want allow duplicate digits (y or n)?"); scanf(" %c", &choice_dup); while (choice_dup != 'y' || choice_dup != 'n') {     printf("\ninvalid entry. please choose y yes , n no.\t");     choice_dup = getchar();     getchar(); } 

the choice_dup assinged char var @ start of main. when run good. when press y or n cant recognize , loop never ends. no matter type. can me , expain me wrong?

the loop run forever because while (choice_dup != 'y' || choice_dup != 'n') evaluate true.

you wanted: while (choice_dup != 'y' && choice_dup != 'n')


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -