Warning by gcc: warning: comparison is always false due to limited range of data type
Your if statement is pointless here: a will never be less than your value of larger than value.
For me it is working correctly giving remainder.
a is probably 32 bits, that means that when you enter a too large number for either ranges(- and +), it'll tend to stick at the highest possible number (according to my experience).
Let's draft a simple solution:
1. Instead of using an integer for direct assignment, use a string.
2. Iterate over the string.
3. if the size of the string > 10
4. - number too high
5. if the size of string == 9
6. - is first element (from left to right) higher than (char)2?
7. if yes, - number too high.
8. Is the first number less than (char) 2?
9. Valid input.
10. Is first number equal (char) 2?
- Check 2nd number equal (char) 1: check next..., if below, valid, if above, invalid.