I have been struggling with the hacker edition of mario.c for over 2 hours. If I give a height of 5 I only get 4 rows as shown in the attached image.
/* C Program which prints mario's right aligned
* half pyramid using hashes */
/* Please note: I obtained a left aligned pyramid by fluke.
* I would like to convert this program to the more
* comfortable (Hacker edition) program */
#include <stdio.h>
#include <cs50.h>
int main(void)
{
// validate user's input
int height;
do
{
printf("Height: ");
height = get_int();
}
while (height <= 0 || height >= 23);
// Here comes the pattern of rows and spaces
for (int rows = 2; rows <= height; rows++)
{
// print spaces
for (int spaces = 0; spaces <= height - (rows + 1); spaces++)
{
printf(" ");
}
// now comes the left hashes
for (int left_hashes = 1; left_hashes <= rows; left_hashes++)
{
printf("#");
}
// the space in bewtween
printf(" ");
// right hashes
for (int right_hashes = 1; right_hashes <= rows; right_hashes++)
{
printf("#");
}
printf("\n");
}
}
when I run check50
this is what I get
:) mario.c exists.
:) mario.c compiles.
:) rejects a height of -1
:( handles a height of 0 correctly
did not find EOF
:( handles a height of 1 correctly
expected "# #\n", not ""
:( handles a height of 2 correctly
expected " # #\n## ##\n", not "## ##\n"
:( handles a height of 23 correctly
timed out while waiting for program to exit
:( rejects a height of 24, and then accepts a height of 2
expected " # #\n## ##\n", not "## ##\n"
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""
Could someone please suggest..
Many thanks in advance..