-
Aug 22nd, 2009, 07:03 AM
#1
Thread Starter
Addicted Member
[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?
-
Aug 22nd, 2009, 07:06 AM
#2
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.
-
Aug 22nd, 2009, 07:09 AM
#3
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|