0

I know this question has been asked several times but I haven't found an answer that worked for the issue I have. The output for my pset1 Mario more comfortable seems to be correct (including no extra spaces at the end of the second pyramid) yet I get this from check50 :

:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) rejects a height of 0
:( handles a height of 1 correctly
    expected ""#  #"", not ""#""
:( handles a height of 2 correctly
    expected "" #  #"\n"##  ...", not "" #"\n"##""
:( handles a height of 8 correctly
    expected ""       #  #"\...", not ""       #"\n" ..."
:( rejects a height of 9, and then accepts a height of 2
    expected "" #  #"\n"##  ...", not "" #"\n"##""
:) rejects a non-numeric height of "foo" 
:) rejects a non-numeric height of "" 

this is what my code looks like :

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

int main(void)
{
    int n;
    do
    {
        n = get_int("height: ");
    }
    while (n < 1 || n > 8);
    for (int i = 0; i < n; i++)
    {
        for (int k = n-i-1; k > 0 ; k--)
        {
            printf(" ");
        }
        for (int j = 1; j <= i+1; j++)
        {    
            printf("#");
        }
        {
            printf("  ");
        }
        for (int l = 1; l <= i+1; l++)
        {
            printf("#");
        }
      printf("\n");
    }
}

This is the output I get when I replace the white spaces with "." :

.....#..#
....##..##
...###..###
..####..####
.#####..#####
######..######

I can't figure out where I went wrong even after checking all the previous answers to this question because most of the time the issue was extra spaces after the right pyramid, but I don't have those.

3 Answers 3

0

Maybe it's the useless brackets you have around printf(" "); Try to remove it and give it another try;

1
  • I removed it but still get the same issue with check50 afterwards
    – Rose
    Commented May 4, 2020 at 14:18
0

Maybe you should try to set all of that equal to a string, then use it in a printf.

0

After submitting the code and still getting 100% I realized that because I have both mario more and mario less in the same directory, check50 was checking for mario more errors on the mario less file. Switching the file to a different directory solved the problem.

You must log in to answer this question.

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