2

I am sorry if I miss something obvious here, but I am an absolute beginner. I get the following output from check50, which I am confused about:

enter image description here

I will attach my code below, but my output for 2 is:

enter image description here

enter image description here

To me those two outputs seem alright? I attach my code below sorry if it's not great:

int pyramid_height;

// Prompt user for pyramid height and check if value is
// between 0 and 23

do
{
    pyramid_height = get_int("Pyramid height: ");
}
while (pyramid_height < 0 || pyramid_height > 23);

// Printing pyramid and adding space and #

for (int x = 0; x < pyramid_height; x++)
{
    int y;

    // Left Pyramid

    for (y = 0; y < (pyramid_height - x) - 1; y++)
    {
        printf(" ");
    }

    for (int r = 0; r < (pyramid_height) - y; r++)
    {
        printf("#");
    }

    // Space Between Pyramids

    for (int q = 0; q < 2; q++)
    {
        printf(" ");
    }

    // Right Pyramid
    for (int r = 0; r < (pyramid_height) - y; r++)
    {
        printf("#");
    }

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

    printf("\n");
}
2

What the eye cannot detect......the check50 output will reveal.

Notice the difference between what is expected and what is detected:

enter image description here

There is an extra "space" between the final # and the \n.

0

I know you printed pyramid_height - x spaces then pyramid_height - y #s then 2 spaces between then pyramid_height - y #s then pyramid_height - w spaces then this threw the error The error means you don't need to print spaces at the right pyramid because its of no use. Not printing spaces at the right pyramid will result to same visual output.

You must log in to answer this question.

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