Input is not valid until y,Y,n,N is inputted

#include<stdio.h>
int main ()
{
char x;

printf(“Input a letter:”);
scanf(“%c”,&x);

while(x!=‘y’ || x!=‘Y’ || x!=’n’ || x!=’N’)
{
printf(“Input a letter:”);
scanf(“%c”,&x);
}

printf(“The input is valid”);

return 0;
}



I cant find my mistake, but the output keeps on showing double "Input a Letter"
Last edited on
while (x != 'y' && x != 'Y' && x != 'n' && x != 'N')

A bit easier:
1
2
3
#include <ctype.h>
x = toupper (x);
while (x != 'Y' && x != 'N')
Hi,
Try && instead of ||
while(x != ‘y’ && x != ‘Y’ && x != ’n’ && x !=’N’)
Does that help you? :)
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <ctype.h>

int main ()
{
   char x = '\0';

   while(toupper(x) != 'Y' && toupper(x) !='N')
   {
      if (x != '\n')
      {
         printf("Input a letter: ");
      }
      scanf("%c", &x);
   }

   printf("The input is valid\n");

   return 0;
}


Input a letter: a
Input a letter: B
Input a letter: N
The input is valid
Topic archived. No new replies allowed.