Need help my while loop in my program seems not working

dear sir

I want to write a program for printing “Hello World” & then ask for reprinting in y/n. if answer “c” is

c!= ‘y’ or ‘Y’ or ‘n’ or ‘N’ then it ask Enter the correct decision

‘n’ or ‘N’ then exit from loop

‘y’ or ‘Y’ then again printing “Hellow World” & then again repeat

I write my program as given below. in this problem highlighted while loop " while((c!=‘n’||c!=‘N’)||(c!=‘Y’||c!=‘y’))" is not working properly.

in this loop if I enter c=n or y then this loop is executed rather than get out from the loop which should be wrong. kindly tell me in this while loop where I did a mistake?


#include <stdio.h>

int main()

{

char c;

int x[100];

do{

printf(“hello world\n”);

printf(“r u want to continue y/n=”);

scanf(" %c",&c);

if(c==‘n’||c==‘N’)

break;

while((c!=‘n’||c!=‘N’)||(c!=‘Y’||c!=‘y’))

{

   printf("\nEnter the correct decission=");

   scanf(" %c",&c);

}

if(c==‘n’||c==‘N’)

break;

}

while(c==‘Y’||c==‘y’);

return 0;

}

I think you should use first if statement to check if the first input is not n or y, and if not, only then you should enter the while loop

Even if you enter a Y or N, one of these conditions will be true and it will enter the loop. If you enter Y, (c!=‘n’) will be true. You should rather use AND instead of OR. Or you could also do this :

while( ! ( c=='n' || c=='N' || c=='y' || c=='Y')

Hope this clears your doubt.

Yea, that’ll work find too

my problem is solved