I am working on a simple video game program for school and I have created a method where the player gets 15 health points if that method is called. I have to keep the health at
just add 15 to the health, so:
health += 15;
if(health > 100){
health = 100;
}
However, as bland has noted, sometimes with multi-threading (multiple blocks of code executing at once) having the health go over 100 at any point can cause problems, and changing the health property multiple times can also be bad. In that case, you could do this, as mentioned in other answers.
if(health + 15 > 100) {
health = 100;
} else {
health += 15;
}