Thread: If Else statements

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    If Else statements

    I don't know how to include lower case a-z or upper case A-Z in a if else statements

    thanks in advance.

    If oneChar between 'a' ... 'z' or 'A' ... 'Z', then returns
    // true, else, returns false.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Take a look at some C string/character functions.
    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

  3. #3
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    ascii value of A-Z is 65 to 90
    and a-z is 97 to 122

    sample:
    Code:
    char b = 'b';
    
    if( b <= 65 && b >= 90 )
       return true;

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by rdave1
    I don't know how to include lower case a-z or upper case A-Z in a if else statements

    thanks in advance.

    If oneChar between 'a' ... 'z' or 'A' ... 'Z', then returns
    // true, else, returns false.
    Code:
    bool is_a_to_z( char c ) {
       return (( c >= 'a' && c <='z' ) || ( c >= 'A' && c <='Z' ) );
    }
    and use it like this
    Code:
       char c;
       cin >> c;
       if ( ! is_a_to_z(c) ) {
            cout << "illegal chracter '" << c << "'" << endl;
       }
    is that what you are looking for ?
    Kurt
    Last edited by ZuK; 09-15-2005 at 09:43 AM.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Of course you all are assuming ASCII wish isn't required. Since it appears that you want to know if its an alphabetic character why not just use isalpha()?

  6. #6
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Thantos
    Of course you all are assuming ASCII wish isn't required. Since it appears that you want to know if its an alphabetic character why not just use isalpha()?
    And you are assuming english char-set. In other char-sets there are more char's for witch isalpha() would return true.
    On the other hand there are few questions on this board that can be answered without any assumptions.
    Kurt

  7. #7
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Quote Originally Posted by Thantos
    Of course you all are assuming ASCII wish isn't required. Since it appears that you want to know if its an alphabetic character why not just use isalpha()?
    Quote Originally Posted by ZuK
    And you are assuming english char-set. In other char-sets there are more char's for witch isalpha() would return true.
    On the other hand there are few questions on this board that can be answered without any assumptions.
    Kurt
    indeed indeed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. C++ If Statements Help
    By moporho in forum C++ Programming
    Replies: 19
    Last Post: 01-18-2008, 08:40 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Need help with "if" statements
    By Harryt123 in forum C Programming
    Replies: 22
    Last Post: 05-14-2006, 08:18 AM