0

so I thought I had finally completed Pset1 and went back to mario to do the check50, and well it doesn't seem to like my code, and I can't see where I am going wrong, another pair of eyes would be greatly appreciated.

Here is the code:

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

int main(void)
// prompt user for height of half-pyramid
{
    int height;
do
{
    printf ("height: ");
    height = GetInt();
}
while ((height < 0) || (height > 23));

// print the half-pyramid
int row, space, hash;

for (row = 0; row < height; row++)
{
for (space = height - 1; space >= row; space--) 
{
    printf (" ");
}
{
    for (hash = -1; hash <= row; hash++)
    {
    printf ("#");        
    }
    printf("\n");
    }

}
}

And here is check50s response:

:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) handles a height of 0 correctly
:( 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"
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""

Thank you

1 Answer 1

0
for (space = height - 1; space >= row; space--)

All of the program's problems are in this one line, check your conditions and logic here and you should find your problem. Other than that, the program is fine except for a few extra curly braces.

1
  • Thank you so much - finished pset1 now, woohoo!
    – Sofia
    Commented Dec 8, 2016 at 16:57

You must log in to answer this question.

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