Your code mearly prints "*" six times for every loop of x, and loops x 7 times. Think about what x and y mean. If y means row, how many times do you want it to run through? If x means collumn, how many times do you want it to run through, as a function of the row? You have the current row, y. Remember, that even if you're printing z, it will print it at the current cursor position.
I've heard it takes forever to grow a woman from the ground
ok, another hint We can use our's logic to think about how to use for loop For the first line, print five stars and the second line, print four stars third line, print three stars last line, print 1 stars. We can see the relationship between number of line and number of star that you need to print it out. So the the y variable in the outer for loop has close relationship with the x variable in the inner for loop. We can think about y=number of line and x=number of stars. If you know how to establish the relationship, then it works. [ November 07, 2004: Message edited by: siu chung man ]
Um.......... I could give you an answer but it must be better that you do the assignment by yourself, as I mentioned before, could you try to establish the relationship between the following two nested loop? for ( int y = 1; y < 6; y++ ) for ( int x = 5; x > 0; x-- )
I give you another example then you can convert the idea to get the answer from the original question Do you know how to print the following pattern? * ** *** **** ***** If you know, then you can solve your question successfully. The relationship is x=y in the above example. Of course, you need to convert your code from the starting point x=1 to x=5 and y=x.........
[ November 07, 2004: Message edited by: siu chung man ]
I don't think that is the point that siu is trying to make. Take a look at each row. How many *'s do you want to print in row 1? How many in row 2? (and so on) Can you see a relationship between the row number and the number of *'s in the row? How can this relationship help you decide how many times to execute the inner loop?
Try answering these questions. I hope it will give you an insight into finishing this program (if you haven't done it already, that is).
p.s. This program doesn't require an array. I see that you aren't using it in your for loop any more, so you might as well remove the declaration as well.
You know..sometimes my head just does not work for programming. Thanks for all your help guys, I got it working. Layne cleared up what the others where trying to get through my thick head hehe . Here's the code if your interested.
Normally trees don't drive trucks. Does this tiny ad have a license?