WHILE LOOP problem

This is a discussion on WHILE LOOP problem within the C++ Programming forums, part of the General Programming Boards category; uggg....oh man i will probably figure it out before anybody respods but just incase i don't here's my problem. it's ...

  1. #1
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256

    WHILE LOOP problem

    uggg....oh man i will probably figure it out before anybody respods but just incase i don't here's my problem. it's soo anoying

    i'm asking the user to enter n (notice small) if they don't want the program to continue, but when they press 'N' (notice capital) my loop just continues. so i tried fixing it with this statement:

    while(ch!='n' || ch!='N')

    but now the problem is that the loop continues if the user enters n or N. not what i want. i want the program to exit when the user enters n or N. any thoughts on this would be greatly appreciated. thx

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    while(ch!='n' && ch!='N')

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    ... or use toupper() and then only test against capitals.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    ok, thanks to polymorphic, i used && instead of || (if you don't know what i'm talking about read my problem up top) . but why &&?

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    || is "or"
    && is "and"

    Read the logic of the test, and you should understand. You want both tests to be true to keep the loop going.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256

    Talking

    YES HAMMER!!!! THANK YOU SOOOOO MUCH!! IT ALL MAKES SENSE NOW!! WQOOOOHOO! I'M SO HAPPY! THANK YOU SOO MUCH!!!!!!!!!!!!!!!!!!!!!!!!!

    the last few words in your reply made all the difference in my understanding!

    oh my blush! thanks alot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21