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");
}
}