Thread: Looping Activity

  1. #1
    Registered User
    Join Date
    Aug 2014
    Posts
    17

    Lightbulb Looping Activity

    You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :


    Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.


    OUTPUT must be:


    n = 5
    0
    1==0
    2==1==0
    3==2==1==0
    4==3==2==1==0
    5==4==3==2==1==0


    if n = 6
    0
    1==0
    2==1==0
    3==2==1==0
    4==3==2==1==0
    5==4==3==2==1==0
    6==5==4==3==2==1==0

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you start with something like this:
    Code:
    #include <iostream>
    
    int main()
    {
        int n = 5;
        // ... loop and print the integers from 0 to 5 inclusive ...
    }
    So, this program will print the simplified output:
    Code:
    0
    1
    2
    3
    4
    5
    then you change to n = 6, recompile and run the program to check.

    After that, work on a program that would, depending on the value of n, print something like:
    Code:
    5==4==3==2==1==0
    After you have formulated and implemented an algorithm that does that, combine what you learnt from the two programs to implement a program with output like:
    Code:
    0
    1==0
    2==1==0
    3==2==1==0
    4==3==2==1==0
    5==4==3==2==1==0
    When you are done with this part, then finally add in code to satisfy these requirements:
    Write a program that accepts a positive integer. (...) Use do while to allow the user to continue or not.
    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

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > where she haven't taught this to us yet.
    So is there a problem with you reading the next chapter of the book? One entitled "loops" would be a good start.

    Also, 99% of programming experience comes from you driving yourself, not from sitting in class listening to someone read a book to you.

    See if you can at least figure enough out to print the first column of numbers.


    Announcements - C++ Programming
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    If you have a basic text or reference handy, look up the words "looping" or "for loop" or "flow control". If using google, add the string "C++" to those search strings.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Aug 2014
    Posts
    17
    Thanks for sharing some good information regarding C++ Looping.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    In addition to thanking the people who offered you advice in this thread, perhaps you should also issue an apology for wasting their time by cross-posting until you got handed an answer. It seems you were just after a solution and not interested in using the advice that people so generously gave their time to give you.

    In addition to this thread, you also got pretty clear advice here, though you still didn't seem interested in actually trying to apply it.

    Then some over-enthusiastic poster here gave you the whole thing, and you called it a day.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mouse activity
    By rogster001 in forum C Programming
    Replies: 2
    Last Post: 09-03-2009, 05:52 AM
  2. Activity Monitoring Program
    By kyourin in forum C++ Programming
    Replies: 0
    Last Post: 06-22-2009, 12:20 AM
  3. Get HDD Activity
    By leandroaz in forum C++ Programming
    Replies: 13
    Last Post: 10-10-2008, 12:28 PM
  4. logging key activity
    By threahdead in forum C Programming
    Replies: 1
    Last Post: 10-03-2002, 01:05 AM

Tags for this Thread