0

I need some help figuring out how to change the number of spaces on each line of the pyramid. The pyramid comes out with 5 spaces at the beginning of each line instead of 4, then 3 then 2, etc. I thought that by telling the print_row function that the input for "spaces" would be the height indicated by the user minus 1, and then subtracted by one each time it goes through the loop should achieve this but I'm stuck. Thanks in advance for any help! Code for mario pyramid

1
  • please put your code and output in the question directly and not via an image
    – UpAndAdam
    Jan 5 at 17:33

1 Answer 1

1

The problem is line 20. The value of n never changes. You need to figure out a way to have the value being passed to decrement with each loop, instead of just n-1 each time.

hint: is there any relationship between n and i that could be used?

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

4
  • Thank you, Cliff. I thought that the "i--" was what would decrement the value with each loop? When I try to use n in the loop for spaces it gives me the error that n is an undeclared variable.
    – AmyG
    Jan 7 at 3:46
  • I changed the code on line 20 to read: print_row (n, i + 1) and the code on line 26 to read: for(int i = spaces - 1; i > 0, i--), But I'm still getting the same number of spaces on each line. Thank in advance if you can offer me any more help!!
    – AmyG
    Jan 7 at 3:53
  • It's still the same problem. On line 20, n never changes, while i+1 gets larger on each pass. Think in terms of something like a-b. (I'll let you think about what a and b really are.)
    – Cliff B
    Jan 7 at 22:38
  • Thank you, I was able to fix it now.
    – AmyG
    Jan 9 at 1:27

You must log in to answer this question.

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