If question ?

This is a discussion on If question ? within the C++ Programming forums, part of the General Programming Boards category; Code: if(input == "mom" || "Mom" || "MOM" || "MOm" || "moM" || "MoM" || "mOM" || "mOm") { if(mom ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    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
    22,269
    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>.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10: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


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