1

When I run my code with make mario and ./mario, everything works fine with user input. I can enter any integer and I get the correct result. But when I enter check50, I get this result:

:) 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 ""

Why does check50 not work when my code works fine with user input?

This is my code:

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

int main(void) 
{
    int n;
    do {
        printf("Height:");
        n = GetInt();
    }
    while (n > 23 || n < 0);

    for (int b = 0, c = n; b < n; b++, c--)
    {
        for (int z = 0; z < c; z++)
        {
            printf(" ");
        }
            for (int y = -2 ; y < b; y++)
            {
                printf("#");
            }
            printf("\n");
    }
}
1

check50 expects very exact output. Anything extra or missing, a prompt, character, space, line feed, whitespace, etc., will generate a failed test result.

In your case, it may look right to you, but it isn't. There's an extra space at the beginning of every line of the pyramid.

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

2
  • Wow. Thanks, I didn't notice that there was an extra space. I was able to fix the problem by changing z=0 to z=1 – Lucas Nov 4 '16 at 1:13
  • Glad you fixed it. If you're happy with the answer above, please click on the check mark to accept it, so that it is removed from the unanswered question pool. thanks. – Cliff B Nov 5 '16 at 7:51

You must log in to answer this question.

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