# Coding for "every 17th"

• 06-14-2004
Zewu
Coding for "every 17th"
I have this loop where I want an event to occur for every 17th turn.

Code:

```for(float i=1.00; i<=k; i++)         {                 if((i*i)>=100)                 {std::cout << "\n    " << i << "    |        " << i*i;}                 else {std::cout << "\n    " << i << "    |        " << i*i;}                 if((i/17)==(int))                 {std::cout << "\n\n\n\n\n"; system("PAUSE");}         }```
Never mind about whether I use float etc. I found a way for expressing every 17th to be that i/17 would be equal to an integer. I.e. 17/17==1, 34/17==2, 51/17==3 etc.

Neither do I know a way to express "integer", nor do I know any other way to solve this problem.

Feel free to help me with both these tasks.
• 06-14-2004
Epo
Instead of using division, could you use modulus? (The % operator) Which returns the Remainder.

So:
1 % 17 = 1
5 % 17 = 5
17 % 17 = 0
20 % 17 = 3
34 % 17 = 0
51 % 17 = 0

And that way, just check when i % 17 = 0 (meaning the i value is divisible by 17 with no remainder) and fire the event then?
• 06-14-2004
Zewu
Of course. I tried that and it solves it all. Thanks alot