Thread: Validating entries of type double

  1. #1

    Post Validating entries of type double

    Okay, I'm writing a program which will allow the user to input double values into an array until the array is full or the user enters non-numeric input. I've tried using with a while loop, which works fine for invalid input like:


    However, if the user enters something like:


    The cin will read it in until a character is reached and then it has not failed. It only fails after the numbers. How do I get it to exit the loop when this happens, without storing the 123 of 123T into the array, etc.

    Help is much appreciated.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    maybe you could read it as a string and reject the whole thing if any non numerical parts are in it. that seems wasteful, though. my 2 cents.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  5. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM