Results 1 to 3 of 3

Thread: [RESOLVED] Check For Multiple Of 20

  1. #1

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Resolved [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?

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  3. #3

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    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
  •  



Click Here to Expand Forum to Full Width