Check amount of digits

Whats the faster way (fewest lines of code)to check amount of digits a user enters.

for example i have

struct money
{
int value1, value2;

};

int main()

{
money twenty;
cout << "Enter value 1(2 digits): ";
cin >> twenty.value1;
// how can i check here and warn user if they put more than 2 digits?
cout << "Enter value 2(4 digits): "
cin >> twenty.value2;

return 0;
}
if(value1 > 99 || value1 < -99)
what? that makes no sence
A number that is larger than 99 does have more than two digits, doesn't it?

Logical OR (||) is true, if either of its two operands is true.

The if is a test. If the condition is true, then the value1 has more than two digits.

It is hard to have less than one line of code.


Note though that "short" does not always mean "fast". Besides, there are many ways to be fast:
* Fast to write
* Fast to compile
* Fast to execute
* Fast to understand
Topic archived. No new replies allowed.