0

i am trying to make the loop stop after typing y/n, but it just returning printing and asking for a char. what is wrong here?

code:

char con='r';

while(con != 'n' || con != 'y')
{
    printf("Would you like to play again? (y/n): ");
    con=getch();
}
linoiushi
  • 47
  • 6

1 Answers1

2

Note your while condition; One of the two conditions is always true, therefore the while condition is always true.

Change it to:

while (con != 'n' && con != 'y')
Yaniv Shaked
  • 698
  • 6
  • 12