# How to check if variable is equal to range of integers

I’m trying to make a scoring system for my game where backgrounds will change upon meeting a certain condition. So I have a variable int “SCORE”, every time my player game object collides with a variety of loots inside my scene, SCORE is incremented by 1 or by 4 points. My condition to change background is if the SCORE is equal to 11 or up to 14. Is there much easier way to write that logic?

this is what I have tried so far:

``````  void checkpoint() {
``````
``````    if (SCORE == 11 || SCORE == 12 || SCORE == 13 || SCORE == 14 )
{
changeBG();
}
if (SCORE == 20 || SCORE == 21 || SCORE == 23 || SCORE == 24)
{
changeBG();
}
}
``````

but every time the SCORE hits those integers inside the condition the changeBG method is called again.

You should use greater than or equal to `>=` and less than or equal to `<=`

``````if (SCORE >= 11 && SCORE <= 14 )
{
changeBG();
}
else if (SCORE >= 20 && SCORE <= 24)
{
changeBG();
}
``````

Your numbers / ranges looks a bit weird. Are you sure you want to start the second range at 20 and leave out 22?

If you just want to change the background whenever the level number ends in 1, 2, 3 or 4 you can simply do:

``````int tmp = SCORE % 10;
if (tmp >= 1 && tmp <= 4)
{
changeBG();
}
``````

This would call changeBG at a score of 1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42, …

of course if you want to start this pattern at 11 and not at 1 you can add an additional condition

``````if (SCORE >= 11 && tmp >= 1 && tmp <= 4)
{
changeBG();
}
``````