• Advertisement
Sign in to follow this  

Help with data protection

This topic is 3358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok so I'm creating a few functions to use in a game someday and I'm wondering something: How would I make a check that would automatically set an entered value to the max of its data type? For instance, I have an unsigned int money. In a console program I have entered a number well over the maximum that an unsigned int can handle, how do I force the program to take a value that is that large and automatically set it as the unsigned int max? Thanks for reading.

Share this post


Link to post
Share on other sites
Advertisement
Store it temporarily in an unsigned long long? Then use pow(256, sizeof(unsigned int))-1, or std::numeric_limits<unsigned int>::max(); to get the maximum number an unsigned int can hold.

Share this post


Link to post
Share on other sites
or the easiest way... don't allow the player to type more than what you can handle :)

Share this post


Link to post
Share on other sites
Or, you could just use the correct library function which already does all that for you.

Quote:
These functions shall return the converted value, if any.
If no conversion could be performed, zero shall be returned.
If the correct value is outside the range of representable values, {INTMAX_MAX}, {INTMAX_MIN}, or {UINTMAX_MAX} shall be returned (according to the return type and sign of the value, if any), and errno shall be set to [ERANGE].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement