PDA

Click to See Complete Forum and Search --> : Multiple conditons in a while loop


mrchaos
Sep 20th, 2002, 11:07 PM
cType = getche();
while (cType != 'C' || 'c' || 'I' || 'i' || 'A' || 'a')
{
printf ("Code not valid");
printf ("\nPlease re-enter a type (I, C, or A): ");
}

how can i put multiple conditions into a while loop? currently, the loop always comes back false.

twanvl
Sep 21st, 2002, 06:19 AM
You must write each condition separatly:
char cType = getche();
while (cType!='C' && cType!='c' && cType!='I' && cType!='i' && cType!='A' && cType!='a')
{
printf("Code not valid");
cType = getche();
}

jim mcnamara
Sep 23rd, 2002, 11:32 AM
how about



for(cType = getche();strchr(cType,"AaCcIi")==NULL;cTYpe=getche() )
printf ("Code not valid\nPlease re-enter a type (I, C, or A): ");

CornedBee
Sep 24th, 2002, 06:58 AM
nope, strchr expects a string as first argument.