Loop Loop...

This is a discussion on Loop Loop... within the C++ Programming forums, part of the General Programming Boards category; hi everyone, can someone give me some hints on how to loop the number from 1 to 23 and after ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    141

    Loop Loop...

    hi everyone,

    can someone give me some hints on how to loop the number from 1 to 23 and after that start from 1 - 23 again and start over again..

    thank you..

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    psuedo
    Code:
    int val = 1
    
    loop{
        //do stuff here
        if val = 23{
            val = 0
        }
        val = val + 1
    }
    Woop?

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    hi, i dont understand ur code as i am newbie of c++..

    my aim is to produce the day of the physical cycle for biorhythm.

    physical day has 23 per cycle...

    hope you understand

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    That was psuedo code. Meaning it wasn't language specific. This is a very simple logic problem and I basically just handed the answer to you so I really don't see the problem.
    Woop?

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    can other person help me about this..
    thnx anyway...

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    can other person help me about this..
    What part of prog-bman's pseudocode do you have problems understanding?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    What do you want someone to do your work for you?
    I am sorry you can't figure out such a simple problem. Obviously my efforts were horrible and you being the genius you are, my feeble efforts are too simple for you to understand so please someone who is more intelligent than I help peter with his ultra difficult logic problem.

    C++ Code
    Code:
    #include <iostream>
    
    int main()
    {
        //This will loop through 1-23 10 times 
        //I am suprised I know how to do this
        int iters = 0;
        for(int i = 1; iters < 10; i++){
            std::cout<<i<<" ";
            if(i == 23){
                i = 0;
                iters++;
                std::cout<<std::endl;
            }
        }
        std::cin.get();
        return 0;
    }
    ^Is me being too nice but whatever
    Last edited by prog-bman; 05-25-2006 at 01:28 AM.
    Woop?

  8. #8
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    cool.. ...............

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Is me being to nice but whatever
    Sorry, prog-bman, your solution is wrong. The specification does not allow for printing the numbers to screen, and requires an infinite loop.

    A correct solution would be:
    Code:
    int main()
    {
    	for (;;) for (int i = 1; i <= 23; ++i);
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    I wasn't going to write his code for him just give a general idea
    Woop?

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    I wasn't going to write his code for him just give a general idea
    Well, now I can claim to be 'nicer' than you
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    You sure are
    Woop?

  13. #13
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Hey, laserlight, check out this link!

  14. #14
    Registered User
    Join Date
    May 2006
    Posts
    28
    Hey, laserlight, check out this link!
    lol

  15. #15
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I see you've clicked this link before!

    Closed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

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