0

I am having some of my checks fail in pset1 mario less. Everything seems to work well when I check it by inputting the checks myself, and I cannot seem to figure out what isn't working. Any suggestions? Thank you.

  int height; //declare variable height

    do
    {
        printf("It's-a-me, Mario!  What is the height of the pyrimid?\nPlease enter a height between 0 – 23\nHeight:"); //welcome statement
        height = get_int();  //get integer for pyrimid height
    }
    while (height < 0 || height > 23); //height requirements for CS50 problem

    for (int row = 0; row < height; row++) //for each row of height, so long as the height is larger then the row number...
    {
        for (int space = 0; space < height - row; space++) //keep adding spaces on the row until the spaces equal the equation to maintain the same number of characters in each row.
        {
            printf(" ");
        }
        for (int hash = -2; hash < row; hash++) //starting with two hashes, keep adding an addtional hashes to each row so long as the hash placement is less then the row number until the last line.
        {
            printf("#");
        }
     printf("\n");   //...go to the next line
    }
}

output:

:( handles a height of 1 correctly
   \ expected output, but not " ##\n"

:( handles a height of 2 correctly
   \ expected output, but not "  ##\n ###\n"

:( handles a height of 23 correctly
   \ expected output, but not "                       ##\n            ..."

:( rejects a height of 24, and then accepts a height of 2
   \ expected output, but not "  ##\n ###\n"
1

The problem is that there is an extra space at the beginning of each line of the staircase.

In my previous (and now removed) first answer, I misread the output from check50, which can easily be interpreted to look like the stairs were facing the wrong way. My bad. ;-)

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

1
  • It is justified as it should be. The problem again with extra space.
    – obesman
    Jul 5 '17 at 4:40
0

Run ./mario. Then staff solution ~cs50/pset1/mario for the same height. You should note the difference.

You must log in to answer this question.

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