user6923745 user6923745 - 1 year ago 194
C Question

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
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++)


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download