Comparing Chars

This is a discussion on Comparing Chars within the C++ Programming forums, part of the General Programming Boards category; How would I compare a char? Say a do-while statement that checked if a char was equal to Y or ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    59

    Comparing Chars

    How would I compare a char? Say a do-while statement that checked if a char was equal to Y or y.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    do {
      // Stuff
    } while ( ch == 'Y' || ch == 'y' );
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    You can make life easier by converting to either upper or lower case..but dont forget to #include <ctype.h>


    char ch;

    do
    {
    cout << "enter letter";
    cin >> ch;
    ch=toupper(ch);
    ...
    }while (ch=='Y');
    simple is always an understatement.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems Comparing Char's
    By MrKnights in forum C++ Programming
    Replies: 2
    Last Post: 07-05-2007, 02:49 PM
  2. comparing chars
    By jaxlle in forum C Programming
    Replies: 5
    Last Post: 12-27-2006, 12:00 PM
  3. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 05:29 PM
  4. Comparing Chars
    By drdroid in forum C++ Programming
    Replies: 12
    Last Post: 02-26-2002, 02:06 PM
  5. comparing chars with pointer to char
    By papous in forum C Programming
    Replies: 5
    Last Post: 11-24-2001, 01:23 AM

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