c - Help with getch() function -


i want use getch function character... user can enter y or n character.. while loop not working... need help! thanks

#include <stdio.h> main(){    char yn = 0;     printf("\n\t\t  save changes? y or n [ ]\b\b");    yn = getch();    while (yn != 'y' || yn != 'y' || yn != 'n' || yn != 'n') {   //loop not working          yn = getch();    }      if (yn=='y' || yn=='y') printf("yehey");     else printf("exiting!");      getch(); } 

yn != 'y' || yn != 'y' || yn != 'n' || yn != 'n'

you need use && instead of || here. have entered 'y'. 1st test yn != 'y' false 2nd test yn != 'y' true. condition true, ored. that's why entering loop again.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -