PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 21, 2022

[FIXED] How do I make an Int in C++ have a limit?

 July 21, 2022     c++, integer     No comments   

Issue

Is there any way I could ensure an int doesn't cross a certain limit? and if it needs to (if the program is adding numbers to the int and it crosses the limit) it goes back to 0 and does the job from there?


Solution

It sounds like you want the modulo operator %.

If the upper limit is limit then

value = value % limit;  // Or value %= limit

will "reset" the value back to zero if it's about to pass the limit.



Answered By - Some programmer dude
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing