Thread: Help with checking numbers

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

    Help with checking numbers

    Hi All,

    I am doing an assignment at college to produce a calculator which will only accept a maximum of 6 digits, including the decimal place.

    The only thing i am struggling with is how to check that the user hasnt entered more than 6 digits...


    Does anybody know of a tutorial i could look at?

    or is this a simple thing todo?


    Thanks alot for your help guys

    Boontune

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you read it as a string, check if strlen(InputString) <= 6.
    For integers, divide the number by 1000000. If the result is greater than or equal to 1, it's more than 6 digits.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    Thanks Magos,

    That worked a treat!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  2. Checking for letters
    By brdgsa in forum C Programming
    Replies: 2
    Last Post: 12-05-2002, 10:20 AM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM