user6923745
user6923745

Reputation: 13

CS50 Mario Pyramid - The code works, but I'm still getting errors when I run check50

When I run this code, I do get the desired result of a right-aligned pyramid that varies by user-input height. However, when I run the CS50 check function, it tells me the following:

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

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

int main(void)
{
    int height;
    int row;
    int space;
    int hash;
     // declare variables 
    do 
    {
        printf("Height:\n");
        height = GetInt();
    }
    while (height < 0 || height > 23);

    // build pyaramid if acceptable height entered

    for (row = 0; row < height; row++)
    { 

        for (space = 0; space < (height - row); space++)
        {
            printf(" ");
        }
        for (hash = 0; hash < 2 + row; hash++)
        {    
            printf("#");
        }    
        printf("\n");
    } 

}

Upvotes: 0

Views: 1853

Answers (1)

Michael McGuire
Michael McGuire

Reputation: 26

Are you sure you're getting the right output of spaces? I remember Mario.c is supposed to output a pyramid that's right aligned, but also has the bottom-left aligned with the terminal side. It may be hard to tell since it's empty space. I suggest testing it by printing a character in its place

For example

for (space = 0; space < (height - row); space++) { printf("b"); }

That should give you an idea of what you need to change.

Upvotes: 1

Related Questions