0

I thought had solved the Mario Pyramid problem until I got back all these errors

:( handles a height of 1 correctly
Cause
expected ""#  #"", not ""       #  #  ..."


:( handles a height of 2 correctly
Cause
expected "" #  #"\n"##  ...", not ""       #  #  ..."

...and so on.

Any clues to where I've gone wrong? My code below:

..............

#include <stdio.h>
#include <cs50.h>

int main()
{
    int row, col, n;

    do
    {
        n = get_int("Ladder height:");
    }
    while (n > 8 || n < 1);

    for (row = 1; row <= n; row++)  // Loop to print rows
    {
        for (col = 1; col <= 18; col++) // Loop to print columns    
        {
            if (col == 9 || col == 10 || col <= 8 - row || col >= 11 + row)// Pyramid
            {    
                printf(" ");
            }    
            else    
            {
                printf("#");
            }
        }

        printf("\n");
    }    
    return 0;    
}
1

The code doesn't satisfy the program spec. Too many leading spaced for all except a pyramid of height 8. The last line of a pyramid of any height must start in the first position on the line.

This code positions the pyramid as if it has 8 lines no matter how many lines are in the pyramid.

In other words, if the pyramid has only one line, the first char on the line should be a #, not a bunch of leading spaces.

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 .