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

1. ## 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. 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.

Popular pages Recent additions