1

I have read and re-read through the help provided for mario here and other places, but am stuck at getting the right number of lines, but not the right characters in each line (i am substituting a for spaces to be able to view clearly). I am very right brained, so need help using non-technical language. Any guidance would be appreciated. Code to date below. Thanks.

int main(void) { //ask user how many blocks to make mario jump

int n;

do
{
     printf("How many blocks would you like Mario to jump?\n");
     n = GetInt();
     printf("Height: %i\n", n);
}
while (n < 1 || n > 23);


//create pyramid

for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
    {
        printf("a");
    }

    for (int k = n; k < n + 2; k++)
    {
        printf("#");
    }
    printf("\n");
}

}

1

I think you have it the other way around, you are getting the correct number of lines (height n) but the wrong combination of characters per line. Your code generates 4 a's and 2 #'s for each line. For this you want to work it out with pen and paper first using some of your left brain.

For the bottom line (i=0), you want n+1 #'s and no a's. Taking n=8, for example, you get 9 #'s and no a's in the bottom line. The one above that (i=1) has 8 #'s and 1 a. See the pattern? Just set the conditions of your for loops accordingly, with #'s decreasing by 1 and a's increasing by 1 as you go higher up the half pyramid.

| improve this answer | |

You must log in to answer this question.

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