Thread: How do I add an expression according to the user's input?

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    82

    Question How do I add an expression according to the user's input?

    How do I add an expression(modulus) according to how many digits user's input have?

    Example :

    If,

    User input : 5832 ( 4 Digit )

    4 digit = 4 modulus expressions

    5832 % 10000 , 5832 % 1000, 5832 % 100, 5832 % 10

    If,

    User input : 58320 ( 5 digit )

    5 digit = 5 modulus expressions

    58320 % 100000 , 5832 % 10000, 5832 % 1000, 5832 % 100, 5832 % 10

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There are lots of ways to do this.
    Code:
    if( number > 999 & number < 10000 )
        ... do four digit stuff
    if( number > 9999 && number < 10000 )
        ... do five digit stuff
    You could always just read it as a string and look at each digit individually until you run out of digits.
    You could also just use a loop and keep dividing by 10 and using mod 10 on it.
    I'm sure there are a few more interesting variations out there. You first just have to decide what it is you are actually trying to do.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. user input
    By 182 in forum C++ Programming
    Replies: 14
    Last Post: 02-16-2006, 02:03 PM
  2. Replies: 4
    Last Post: 03-25-2003, 01:23 AM
  3. user input
    By unregisterd in forum C Programming
    Replies: 5
    Last Post: 12-30-2002, 05:22 AM
  4. Best way to get user input?
    By purple in forum C Programming
    Replies: 8
    Last Post: 08-01-2002, 06:43 AM
  5. user input
    By hen in forum C Programming
    Replies: 4
    Last Post: 06-29-2002, 04:10 PM