Results 1 to 4 of 4

Thread: Multiple conditons in a while loop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Burlington, ON, Canada
    Posts
    99

    Multiple conditons in a while loop

    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.

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    You must write each condition separatly:
    PHP Code:
    char cType getche();
    while (
    cType!='C' && cType!='c' && cType!='I' && cType!='i' && cType!='A' && cType!='a')
    {
        
    printf("Code not valid");
        
    cType getche();


  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    how about

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

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    nope, strchr expects a string as first argument.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width