0

I understand the pattern that I need to create. I have drawn it all out on paper. I have watched every single lecture/section/short/walkthrough video. I have Googled. I still don't understand how to make the computer print the right number of spaces and hashes. Please help.

enter image description here

1
  • I can't even figure out how to post my code in a legible way.
    – NikkiT
    May 19, 2015 at 6:42

2 Answers 2

1

The trick in this program is that you should have a for loop for the height (as you did), and then 2 for loops next within this for loop. So like :

for (0 till height preferred)
{
    for (0 till number of blanks needed)
    {        
         printf " "
    }
    for (0 till number of hashes needed)
    {
        printf "#"
    }
    printf ("\n");
}

Good luck!

4
  • Thanks. I tried that and got all kinds of crazy things flashing across the screen, or it stopped printing anything altogether. I will try again.
    – NikkiT
    May 19, 2015 at 12:50
  • I would not use i as counting variable again in the second for loop.... Since you declared it in the previous and higher level for loop. Next to that you might want to use i to keep track of the row your in since that defines how many # and " " you want to print
    – Mihaly
    May 19, 2015 at 13:51
  • What does the i represent, anyway? Iterations?
    – NikkiT
    May 19, 2015 at 21:14
  • 1
    "i" has no particular significance. It is just the traditional variable used as a for loop counter, probably from being the first letter in integer . You could use i, j, fred, count_loops, or anything else that you'd like to use. Traditionaly, i is used as a counter in for loops. With one or more for loops inside another, common practice is to use i for the outer loop, then j for the next inner loop, then k, and so on. However, if the counter variable serves a more complex purpose, you should use a more descriptive variable name instead of a single letter var name.
    – Cliff B
    May 26, 2015 at 22:16
0

Try to bond the nested loops with the variable of the lines "drawer", in a way that when the variable - lets say "lines" - gets from 0 to 1 drawing a new line, to cause a change to the number of spaces... i mean try to make the number of spaces and hashes to be affected by the variable of the lines loop... The outer loop. the one that was made to count the lines after the user input...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .