Min, Max field entry?

This is a discussion on Min, Max field entry? within the C Programming forums, part of the General Programming Boards category; In my program, I have a 4 digit field that the user enters data. How can I code a way ...

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

    Question Min, Max field entry?

    In my program, I have a 4 digit field that the user enters data.

    How can I code a way to recognize and reject the entry if 1,2,3 or 5 or more digits are entered into the field?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    while ( val != 0 ) digits++, val /= 10;
    If digits is not 4 when you're done, handle invalid input.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Max Min Problem
    By smithc2005 in forum C Programming
    Replies: 7
    Last Post: 10-22-2008, 11:38 AM
  2. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 11:02 PM
  3. Game of life
    By JoshR in forum C++ Programming
    Replies: 30
    Last Post: 04-03-2005, 03:17 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

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