Thread: If question ?

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    If question ?

    Code:
    if(input == "mom" || "Mom" || "MOM" || "MOm" || "moM" || "MoM" || "mOM" || "mOm")
        {
                 if(mom == 0 && dad == 0)
                 {
                 cout << "Im not yer mom ..........\n";
                 mom = 1;
                 }
                  if(dad == 0 && mom == 1)
                 {
                 cout << "I told you already im not yer Mother\n";
                 }
                 if(dad == 1 && mom == 0)
                 {
                 cout << "Im not yer Mom Either\n";
                 mom = 1;
                 }
                 if(dad == 1 && mom == 1)
                 {
                 cout <<"Im not yer parent at all u Hoe\n";
                 }
        }
    Why dont that work no matter wat i type it shows this and all the other if commands that have || in them how do i fix this

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    The pattern

    Code:
    if(a == x || y || z)
    Doesn't do what you want. You need:

    Code:
    if(a == x || a == y || a == z)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Hey thanks alot brewbuck :P Cant totally learn from the books

  4. #4
    a newbie :p
    Join Date
    Aug 2008
    Location
    Zurich, Switzerland, Switzerland
    Posts
    91
    Code:
    int len = strlen(input);
    for ( int ix = 0; ix < len; ix++)
    {
         input[ix] = tolower( (unsigned char) input[ix] );
    }
    
    if(input == "mom")
        {
                 if(mom == 0 && dad == 0)
                 {
                 cout << "Im not yer mom ..........\n";
                 mom = 1;
                 }
                  if(dad == 0 && mom == 1)
                 {
                 cout << "I told you already im not yer Mother\n";
                 }
                 if(dad == 1 && mom == 0)
                 {
                 cout << "Im not yer Mom Either\n";
                 mom = 1;
                 }
                 if(dad == 1 && mom == 1)
                 {
                 cout <<"Im not yer parent at all u Hoe\n";
                 }
        }
    i think that would be much better...since you convert first to lower case...

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Umm watever taht is it gives me a error saying wat is the include for that?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    auralius' basic idea is to change all the letters of the string into lower case so you can compare more easily. You can ignore the actual implementation except for the use of tolower() which is found in <cctype>.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

Tags for this Thread