Pset1 Mario - I am able to print out one space and one hash per line baed on the users input number (8 lines, 12 lines, etc) however, i can't seem to get the n+/- equations incorporated with the variable and result in the pyramid shape.

If user enters 4 then i get 4 lines each has one space and one hash. help! how to i incorporate the variables? his is what my output looks like. IF someone is willing to help i can send the code i am using

  • 1
    I think you forgot to paste the output! :) Also paste the code if you like so we can help you better. – ChrisG Aug 29 '15 at 15:12
  • I also recommend this, it will help with critiquing and understanding what you mean – Fijj Oct 29 '15 at 5:27

The easiest way to solve this problem is to draw the pattern for a test case of your choice on a paper. Then count the number of blank spaces and "#" in each line. Please note how these numbers are varying depending on your test case. For ex. Height :5






Here i intentionally replaced white spaces with '&'. The no. of White spaces vary from 4(n-1) to 1 where n=5 and '#' vary from 2 to 6(n+1) If you adjust your limits in the loop like this then you can solve the problem.
You may require three loop,

  1. To change line
  2. To print white spaces
  3. To print #

The way to approach this problem is to do one part at a time. You've already done two - getting the user input and printing out the correct number of lines. Now, break the rest of the problem down into smaller parts. In this case, there are really only two left. One part is to print the correct number of #s on each line. The other is to print the correct number of spaces on each line.

The easiest approach is to figure out how to print the correct number of #s on each line first. Work on that and get it right. Don't worry about the spaces yet. Just get the right number of #s to print on each line. Once that's right, then move on to the last part.

When you have the #s right, figure out how to print the correct number of spaces on each line. Since counting blank spaces isn't easy, print something else first, like @ signs, so that you can count them. Once you are printing the right number of them, just go back and change the @ back to a space in your code.

Another tip: If you are having trouble grasping the big picture, try figuring out how many #'s to print out for one line, then for two, then 3, and so on until you see the pattern. Same for spaces.

The problem looks complicated when you try to do everything at once, but when you break it down into small parts, it gets much easier.

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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