When users enter a number higher than UINT_MAX
, cin
closes it at UINT_MAX
. The value also cannot be negative.
If you need to expand the range, use unsigned long long
for input and enter unsigned int
after verification. This will not protect against numbers that are outside the range of unsigned long long
.
For a universal solution, you can read string
and do the conversion yourself, using unsigned long long
as the result.
source share