telling if a value is alphabetic or numaric?

This is a discussion on telling if a value is alphabetic or numaric? within the C++ Programming forums, part of the General Programming Boards category; is there a way to check if an inputed value is a letter or number? because i have this program ...

  1. #1
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116

    telling if a value is alphabetic or numaric?

    is there a way to check if an inputed value is a letter or number? because i have this program that needs a user to type in a bunch of numbers (0-9) and if you put in a number ever, it automaticly fills everyone with a zero. i tried this:
    Code:
    if(x != 1 && x != 2 && x != 3.... && x != 9)
    {
      cout <<"That's not a valid number";
      b--;       //b is used to count how many ints the have put in, dont want it to think that it was a valid value
    }
    but it didnt work.
    thanks in advance for any help!
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    cctype or ctype.h depending on compiler.

    look up isdigit() and isalpha()

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    If this isnt in the FAQ then it bloody well should be.
    You have two basic strategies.

    1) Get all input as a string and use stringstreams to parse whats needed from the string

    2) Use member functions of the cin object such as clear(),fail(),good(),bad() and ignore() to do the necessary.

    Check the FAQ. there should be examples in it.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 22
    Last Post: 05-28-2008, 06:27 PM
  2. help please..alphabetic sorting.
    By creon in forum C Programming
    Replies: 16
    Last Post: 09-15-2006, 11:34 AM
  3. Names into Alphabetic Order
    By |PiD| in forum C Programming
    Replies: 5
    Last Post: 11-20-2002, 09:15 AM
  4. Who's telling the truth??? Career Advice Needed Badly
    By Ican'tCjax,fl in forum C Programming
    Replies: 1
    Last Post: 11-06-2002, 06:16 PM
  5. Telling how much free memory there is
    By Just in forum C Programming
    Replies: 3
    Last Post: 10-04-2002, 03:06 PM

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