Thread: infinite stupidity

  1. #1
    Village id10t
    Join Date
    May 2008
    Posts
    57

    infinite stupidity

    Code:
    using namespace std;
    int inputAndValidate(char position,int points)
    {
       do{
        cout<<"Please enter the posistion (F or B)"<<endl;
        cin>>position;
        cout<<position<<endl;
       } while(position!='F' || position!='B');
    return 0;
    }
    why does this loop? no matter what input it just loops, please assist the village idiot...
    Last edited by MarlonDean; 05-20-2008 at 04:04 AM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    One of those conditions is always going to be true. A character can't equal 'F' and 'B' at the same time...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Village id10t
    Join Date
    May 2008
    Posts
    57
    Ok i understand it like this

    do the loop while position does not equal f or equal b...

    has my logic gone astray?

  4. #4
    Village id10t
    Join Date
    May 2008
    Posts
    57
    != does mean "does not equal", doesn't it?

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The condition that you are looking for:
    Code:
    while (!(position == 'B' || position == 'F'));
    Which is the same as:
    Code:
    while (position != 'B' && position != 'F');
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Village id10t
    Join Date
    May 2008
    Posts
    57
    Ok ok i got it, I must use && instead of || because no matter what using the || will always result in the condition being true... thanks anon!

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Read the logic out loud:
    Loop while position is not equal to 'B' OR position is not equal to 'F'.

    Or the other one:
    Loop while position is not equal to 'B' AND position is not equal to 'F'.

    Tell me which one sounds most reasonable?
    It's no different than communicating with a friend, for example, on what he or she should do. It's not programming - it's logic!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Where's that thread on boolean math being important for programming?

  9. #9
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2009, 11:24 PM
  2. How to stop an infinite cyle?
    By opsis in forum Linux Programming
    Replies: 4
    Last Post: 01-07-2007, 12:58 PM
  3. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 12:46 AM
  4. Infinite loop
    By osal in forum Networking/Device Communication
    Replies: 1
    Last Post: 06-08-2004, 04:18 PM