Jump to content

Limiting the amount of number a user can enter

- - - - -

  • Please log in to reply
5 replies to this topic

#1
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
So as you already know im still on my final assignment project and is it possible to limit the amount of digits a user can enter?
PePe===> BLACKSPADE EMPIRE<===PePe

www.blackspade-ent.com

#2
Zer033

Zer033

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Nope, it's impossible.

Kidding aside what is it you were doing?

#3
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
lol lets say i want the user to enter a 7 digit number. lets say he enter 8.... its suppose to prompt him saying you entered too many numbers.. i know how to do this with a if statement and single characters but not with entire numbers
PePe===> BLACKSPADE EMPIRE<===PePe

www.blackspade-ent.com

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Well, if it's an int, you can just compare it to 10000000
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Things in life can be so simple lol
PePe===> BLACKSPADE EMPIRE<===PePe

www.blackspade-ent.com

#6
DocSavage

DocSavage

    Newbie

  • Members
  • Pip
  • 7 posts

teensicle said:

...lets say i want the user to enter a 7 digit number. lets say he enter 8.... its suppose to prompt him saying you entered too many numbers..

First, show a code example of what you have so far.
You could do this with a simple array, like:

  char ch;

  char MyArray[10];

  int i, count = 10;


    i = 0;

    while(i < count)

    {

        ch = getche();


        if((ch > 31) && (ch < 127))	              /* ascii chars */

        {

            MyArray[i] = ch;

            i++;

        }

        else if((ch == 8) && (i > 0))           /* backspace */

        {

            MyArray[i] = '\0';

            i--;

        }

    }

    MyArray[count] = '\0';


    if(i >= 7)          /* here is where you test for a valid count */  

    {

        printf("you entered too many numbers\n");

    }  

At the end of user input, a test is made to verify the character count is correct.

*Code not tested, but, the general principle is there.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users