Thread: Loop Loop...

  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,820
    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,820
    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
    28,413
    can other person help me about this..
    What part of prog-bman's pseudocode do you have problems understanding?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,820
    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
    28,413
    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);
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,820
    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
    28,413
    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
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,820
    You sure are
    Woop?

  13. #13
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    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
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM