0

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

Height

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..

1 Answer 1

1

A height of 5 should look like this:

Height: 5
    #  #
   ##  ##
  ###  ###
 ####  ####
#####  #####

so this tells you that are you missing the top row.

Is there a reason that your for loop has the rows starting at 2? If height is 5, then the loop will only run 4 times (when row is 2, 3, 4, 5). You need to make sure that the loop runs height times, right?

Also, be sure to double-check the spec. How large should the gap be between the two halves.


edit

Here is what the Mario More specification shows as an example of a height of 4:

mario more example

2
  • As per the course requirement, the top row should begin with 2 hashes for the less comfortable edition and 4 hashes (2 each) for the more comfortable (hacker) edition.
    – Alok Y
    Sep 8, 2018 at 8:23
  • @AlokY check again. I edited my answer to include a screenshot of the spec. The top row is one hash, 2 spaces, one hash.
    – curiouskiwi
    Sep 8, 2018 at 8:35

You must log in to answer this question.

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