0

I'm having a bit of trouble with my for loops for the less comfortable version of Mario. I set up the outer for loop to keep track of which row is being printed and the inner for loops for printing the spaces, hashtags, and then the \n escape sequence. When I execute the code, the right amount of rows is printed, but the content isn't printed correctly. I've tried testing my code and it seems that there might be something wrong with the outer for loop. I tried taking out the part that prints the spaces and even then, I'm not getting an output with the hashtags. Is there something wrong with the way I'm approaching the outer for loop? I set it up by making a table of the hashtags and spaces on paper and came up with the (pyramid_height - 1 = space) equation, but it seems like I might be missing something that I'm not seeing. Thanks in advance!

for (int i = 0; i < pyramid_height; i++)
{
    for (int space = pyramid_height - 1; space > 0; space--)
    {
        printf(" ");
    }

    for (int hashtag = pyramid_height; hashtag < pyramid_height; hashtag++)
    {
        printf("#");
    }

    printf("\n");
}

}

1

Look at the for loop setup:

    for (int hashtag = pyramid_height; hashtag < pyramid_height; hashtag++)

It initializes hashtag = pyramid_height and immediately tests whether it is less than. This will always fail immediately, so the loop never executes.

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

| improve this answer | |

You must log in to answer this question.

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