[RESOLVED] Check For Multiple Of 20
This is for my game but posted it here as it doesn't specifically relate to game programming.
Basically I have an integer variable called FoodIndex which gets incremented throughout the game. Every time it gets incremented I want to test if it is a multiple of 20 so that I can place A bonus item on the screen.
Any ideas how I can go about this?
Re: Check For Multiple Of 20
You can use the Modulo operator for this.
The Modulo operator returns the remaining part of an integer division.
For example, 22 Mod 5 yields 2, because 22/5 = 20/5 + a remainder of 2.
23 Mod 6 returns 5, because 23/6 = 18/6 + a remainder of 5.
So, if you do FoodIndex Mod 20, it will return 0 if FoodIndex is a multiple of 20 (then, the remainder is zero). It will yield whatever the remainder is if it's not.
Re: Check For Multiple Of 20
Ok thanks a lot sounds like a good way to go about it.
I shall add some reputation for ya