0

So I have a beautiful pyramid, but when I enter any number I get the exact same pyramid, which is the max the pyramid can be.

example: if I enter 5 I get a pyramid of 23. If I enter 15 I get a pyramid of 23.

I realize that it must have something to do with the declared integers but I need them to make my pyramid work. I declare the max height of the pyramid and of the rows of the pyramid.

I use GetInt() and it ask for input and it will keep re-asking until the correct integer is inputted.

Here is the line of code that should determine how tall the pyramid is suppose to be.

for (height = 0; height <= howtall; height++)

height is suppose to be GetInt

howtall is a declared integer of 23.

0

in the first section of the header of your for loop, you're assigning height to 0, so the value that was in there (the one you got from the user) was overwritten and is no longer there. the loop iterates from height is equal to 0 until height is equal to howtall and this is a total of howtall + 1 iterations.

you want your loop to iterate exactly height times not howtall + 1 times. if I told you that

for (int i = 0; i < 10; i++)
{
    // some code
}

iterates exactly 10 times. what would you do to make it iterate height times?

0

You are already declaring the size of pyramid in for loop (i.e howtall=23) Since the height has to be a user input, declare the for loop variable as something else(preferably int i) and set the limit of loop to height (since value of height is taken from user). Like this : (int i = 2; i <= height+1; i++)

You must log in to answer this question.

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