0

I'm running the Mario program and I have everything working except the correct count, which I can fix. The only issue I'm having is a syntactical one. I'm tying to initialize the "for loop" with the variable (height) with the input its getting from (int height = GetInt();. (height) is already initialized above the (do / while loop) and works the way it should. If I code it like this...

for (height = height + 1; height > 0; height++)

That works but can't be syntactically right, plus It's throwing my count off by one. If I remove the +1 it won't work nor will

for (height; height > 0; height++)

if I add

for (int height; height > 0; height++)

I have to give a quantity and I don't know how to do that while still having it reference GetInt

int x = height; (was initialized above the "do loop" in the code below)

 height = GetInt();
        }
            while (height <= 1 && height >= 23);


    for (??? ; height > 0; height--)  
0

Use a dedicated variable for your loops.

CS50 recommend using i for your first loop, then j, then k.

So, initialise int i = height (I'll let you decide if there needs to be a + 1 there), then iterate using i > 0 and i--.

(I'm assuming you didn't mean height++ and height > 0, because that's an infinite loop.)

| improve this answer | |
-1

Just leave those ??? marks empty like for(;height>0;height--)

| improve this answer | |

You must log in to answer this question.

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