1

I have the code for the Mario pyramid written in chunks. The first part runs fine.

I have arbitrarily assigned the height as 8 to compile the program.

When I compile the pyramid, I am running into a problem with the for statement blanks and hashes. I am unsteady with to for statements and would appreciate some suggestions.

enter image description here

3
  • What do you wish to achieve from for (b = x - 2) and similar syntax? Better have a look at how to use a for loop, Google is your friend.
    – sinister
    Commented Feb 4, 2015 at 0:26
  • Number of blanks= height-2 and Number of hashes = height-blanks is what I am trying to accomplish. Commented Feb 4, 2015 at 0:44
  • I did improve the for loop, but I guess where I am struggling is with the LOOP. If I have a for statement can I loop or do I need to go to a do while loop. I know I need to do some math to have the calculations of the blanks and hashes, but where and how? Here is my program so far.dropbox.com/s/23to299meu5l4jq/pyramidv22.c?dl=0 Commented Feb 8, 2015 at 23:35

1 Answer 1

1

Your syntax needs to be cleaned up. A for loop must have an initialization, a condition to evaluate, and an incremental in this format:

for(INITIALIZATION; CONDITION; INCREMENT/DECREMENT) { /* LOOP THIS OVER AND OVER UNTIL CONDITION NO LONGER TRUE */ }

You should also keep watch over the scope of your variables, as I see you've declared all of them outside the for loop.

3
  • I did improve the for loop, but I guess where I am struggling is with the LOOP. If I have a for statement can I loop or do I need to go to a do while loop. I know I need to do some math to have the calculations of the blanks and hashes, but where and how? Commented Feb 8, 2015 at 23:30
  • dropbox.com/s/23to299meu5l4jq/pyramidv22.c?dl=0 Commented Feb 8, 2015 at 23:38
  • I think you're on the right path here, as your For loop syntax looks much better. The "For" is a looping construct that will suffice here, as it will loop according to your initial condition, the condition to evaluate, and the incremental after each trip through the loop. Now that you are able to print a row of characters, try to print a single column of characters. After that, try to generate output where each row has an increasing number of characters. Then start to put it all together where the number of characters to print out can be expressed using variables. You're almost there. Commented Feb 11, 2015 at 4:30

You must log in to answer this question.

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