Thread: loops are sooo confusing

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    6

    loops are sooo confusing

    please can someone copy & paste the source code for the following:
    basically i want to print out the following on the screen:

    *
    **
    ***
    ****

    how would i do this???
    please can someone copy & paste the source code here??
    (btw yes i do mean *'s !!! )

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Let's start from here, what have you tried?

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    6
    I can't find the file cos someone did this for me but basically that's what I want to try.. basically it's just simple with a a nested for loop and i wanna print that pattern

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I don't understand. You know it's a nested for loop, so what exactly is stopping you from analyzing the pattern and doing it? The code you need can be discovered, you just need to persevere. Think about how the outer loop will start the inner loop over, decide what the inner loop needs to do, etc.

  5. #5
    Registered User
    Join Date
    Jul 2013
    Posts
    6
    if you don't mind please can you just do it for me?? if you have a spare moment or so... i mean please can you just write the source code for me??
    cos im just confused.

    no, i mean someone told me it's a nested loop

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    if you don't mind please can you just do it for me?? if you have a spare moment or so... i mean please can you just write the source code for me??
    And what would you do if you needed to write a loop and I wasn't available? :-/

    cos im just confused.
    Well there are lots of different types of loops, but the kind of loop you need is called a counting loop. You can use for loops to do it. The header of the for loop looks like this - for ( start count; count until this number; add to count ) and you loop a set number of instructions, or another loop, like you need to do in the assignment.

    So if you wanted to count from 1 to 5 you could do:
    Code:
    for (int i = 1; i <= 5; i++)
    {
      // statements
    }
    The trick to the assignment is figuring out exactly what you are counting in order to display the shape.

  7. #7
    Registered User
    Join Date
    Jul 2013
    Posts
    6
    i just wanna display : *
    **
    ***
    ****

  8. #8
    Registered User
    Join Date
    Dec 2012
    Posts
    35
    Whiteflags gave you everything you need,the loop is perfect.
    But if you want to do it another way just use printf and finish ....

  9. #9
    Registered User
    Join Date
    Jul 2013
    Posts
    6
    what would the statements be??

  10. #10
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by C lang beginner View Post
    what would the statements be??
    printf("*\n**\n***\n****");

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Honestly, if you don't have the perseverance to try to learn this simple example for yourself, you have no future in programming. You learn by doing - programming is a long and often difficult journey, and at some point you either have the passion to succeed or you will give up. Someone giving you the answer is meaningless; the real trick to programming is learning how to reach the answer. That's why it's so important to try your best on your own first; if you have problems, others can guide you onto the right thought process to advance.

    It would be like showing a chess configuration to a grandmaster and asking what the best move is. If they answered you, what did you learn? You might know an answer to one specific problem, but without understanding the reasoning behind the answer, you didn't learn anything that's useful to any other problem. On the other hand, if you went to the grandmaster, explained what move you would make and why, then actual instruction could happen.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  13. #13
    Registered User
    Join Date
    Dec 2012
    Posts
    35
    Its a preety simple answer,i think its a very nice program for beggining a journey into programming.The thing is there are no shortcuts! Have fun!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C: confusing problem with 'for' loops.
    By thealmightyone in forum C Programming
    Replies: 13
    Last Post: 02-05-2009, 08:23 AM
  2. for loops are confusing me
    By trprince in forum C Programming
    Replies: 3
    Last Post: 11-01-2007, 06:18 PM
  3. sooo close - need a little help
    By bnmwad in forum C Programming
    Replies: 3
    Last Post: 03-06-2005, 02:44 PM
  4. Replies: 16
    Last Post: 11-01-2002, 09:28 PM
  5. I'm Sooo Confused....
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 09-16-2002, 09:35 AM