Thread: checking if input is a number ?

  1. #1
    Unregistered
    Guest

    Question checking if input is a number ?

    Hello all,

    Can someone tell me how to check what a user entered is actually a number and not a character ?

    Thanks in advance.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Look up the isdigit() function in the help. There are other ways too, but try that first.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    If x is an integer, (cin >> x) evaluates to false if the input is non-numeric. Example:

    [code]
    int x;
    cout << "Enter a number: ";
    if(cin >> x)
    {
    cout << "You just input the number " << x << endl;
    }
    else
    {
    cout << "You didn't enter a proper number.\n";
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  3. Replies: 4
    Last Post: 04-21-2004, 04:18 PM
  4. Checking validity of input character
    By yank in forum C Programming
    Replies: 8
    Last Post: 04-16-2003, 02:42 AM