Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How to set minimum and maximum values for an integer?

How do i add minimum and maximum values for an integer? I want an integer to never go down below zero like negative and never goes above 100

Here is the example:

int hp = 100;
std::cout << "You cast healing magic to yourself!" << std::endl;
hp += 20;
mp -= 25;

For example the health is 100 but when a healing magic is cast it became 120. The thing i want is i want it to stay as 100 no matter how many healing magic are cast upon.

Answer*

Draft saved
Draft discarded
Cancel
2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Jun 6, 2022 at 9:17
  • This especially helps, if you would revert lots of changes, if it does not succeed. It would make sense to bundle those variables in a class or struct and make a copy of all of them like a transaction). This case probably is simpler. Commented Jun 6, 2022 at 9:22

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /