Coding for "every 17th"

This is a discussion on Coding for "every 17th" within the C++ Programming forums, part of the General Programming Boards category; I have this loop where I want an event to occur for every 17th turn. Code: for(float i=1.00; i<=k; i++) ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    367

    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.

  2. #2
    Epo
    Epo is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    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?

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    367
    Of course. I tried that and it solves it all. Thanks alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 07:09 AM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 01:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21