3

I'm stuck on the Mario part of PSet1. I've managed to write up my program and the output is always correct (or at least seems to be to me). I know it's definitely the loops that are making things difficult for me. Here are my loops:

for (int i = 0; i < n; i++)
{

for (int a = 0; a < (n - (i+1)); a++)

{
printf(" ");
}

for (int b = 0; b <= (i + 1); b++)
{
printf("#");
}

printf("\n");
}

The output looks exactly the same as it should. However, when I execute Check50, I get the following:

:) 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
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""

I'd really appreciate some help! Thanks!

3 Answers 3

3

check50 is not wrong! Please check this question for more information about check50.

Make sure you're in the same directory as mario.c and this is the command you run to check your program with check50

check50 2014/x/pset1/mario mario.c

Also, your input must match the one required by the pset specification page.

Here's a sample output per the pset specification page

jharvard@appliance (~/Dropbox/pset1): ./mario
Height: 8
       ##
      ###
     ####
    #####
   ######
  #######
 ########
#########

Notice that you should let the user type in the height on the same line as the prompt Height:!

14
  • I'm having the exact same problem. I'm not certain how there are too many spaces or hashes. There are supposed to be two hashes on the top of the pyramid, correct? Is it possible there are to many "\n"'s?
    – user1548
    Commented Jun 28, 2014 at 1:17
  • Am I printing out unneeded spaces, though? For a height of 1, there are no spaces. For a height of 2, there is one space and two hashes on the first row and no spaces and three hashes on the second. Or am I missing something? Is the output supposed to be different? Because I've even [visually] checked my pyramids against the pyramids printed out by CS50's implementation of Mario.c and they look exactly the same... That's what I'm confused about. I understand that I must be wrong, but I can't for the life of me figure out why, or how to fix the issue...
    – cursue
    Commented Jun 28, 2014 at 17:48
  • @Kareem thanks, by the way, for the link and the response!
    – cursue
    Commented Jun 28, 2014 at 17:56
  • @user1548 please check this answer cs50.stackexchange.com/a/1044/1161
    – kzidane
    Commented Jun 28, 2014 at 22:45
  • @sulion are you sure you're printing a newline character at the end of your output?
    – kzidane
    Commented Jun 28, 2014 at 22:52
0

I believe I had the same issue. Make sure that you use printf("\n"); only by the end of your first loop (the one for the rows of the pyramid)!

On my end, the reason for

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

was the fact that the check was not looking into the right row.

1
  • Hi, ivani! Welcome to the SE community! Would you please make your answer clearer? What do you mean "was the fact that check was not looking into the right row"?
    – kzidane
    Commented Jul 3, 2014 at 21:53
0

The answer is pretty easy. The last # has to be with the /n in the end of the big loop.

That's it!

You must log in to answer this question.

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