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

int main(void)
{
    int n;
    do
    {
        n = get_int("Height: ");
    }
    while(n <= 0 || n > 1);

    // Print out first row
    for(int i = 0; i < 1; i++)

         for(int j = 0; j < 1; j++)

        {
            printf("#  #\n");
        }

    do
    {
        n = get_int("Height: ");
    }
    while(n <= 1 || n > 2);

    // Print out second row rows
    for(int i = 0; i < 1; i++)

         for(int j = 0; j < 1; j++)

        {
            printf(" #  #\n##  ##\n");
        }

    do
    {
        n = get_int("Height: ");
    }
    while(n <= 2 || n > 3);

    // Print out third rows
    for(int i = 0; i < 1; i++)

         for(int j = 0; j < 1; j++)

        {
            printf("  #  #\n ##  ##\n###  ###\n");
        }

      do
    {
        n = get_int("Height: ");
    }
    while(n <=3 || n > 4);

    // Print out fourth rows
    for(int i = 0; i < 1; i++)

         for(int j = 0; j < 1; j++)

        {
            printf("   #  #\n  ##  ##\n ###  ###\n####  ####\n");
        }
}

check50 prompts:

:) mario.c exists.
:) mario.c compiles.
:) rejects a height of -1
:( handles a height of 0 correctly
    did not find EOF
:( handles a height of 1 correctly
    timed out while waiting for program to exit
:( handles a height of 2 correctly
    timed out while waiting for program to exit
:( handles a height of 23 correctly
    timed out while waiting for program to exit
:( rejects a height of 24, and then accepts a height of 2
    did not find " #  #\n##  ##\n"
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""
See https://cs50.me/checks/ec2d8ccad685540ee866a2631ba20c6208d7bab4 for more detail.

1 Answer 1

1

Your programme should ask for a number until it gets one in the range of 0 to 23. Then, you should print some stairs of the given height, without any input in between, and end.

The first row might always have two hashes separated by two spaces, but the number of spaces in front varies. And there's also the option for a height of zero, meaning no rows at all. A do..while followed by two nested for loops could do the trick.

Before writing any code, think how you would construct such a set of two half-pyramids, how many spaces, how many hashes to print for each row. You could write an algorithm in your own native language. Small steps, small enough a stupid computer could follow it. Step through that algorithm with pen and paper. Then translate it into code. Computers do what you tell them to do, even if you didn't mean it.

And before running check50, try a few examples in the terminal. If it doesn't work locally, it won't work for check50.

You must log in to answer this question.

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