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.
Idk why is it true for you, try to print out a to see its value.
Although this check is really senseless since a can't be out of that range because it is of type int.
Bourgond Aries, you forgot check of the negative numbers, although this can be simply solved with check if first char is - and if it is increment starting index value.
You're using VC++ which doesn't behave correctly in this regard, from what I can determine, but it does give you a warning that you're blissfully ignoring:
warning C4146: unary minus operator applied to unsigned type, result still unsigned