0

When I run my code in the terminal it gives me the correct response. However, check50 indicates there is an issue with my spaces. I have spend 2 days looking at it but I dont know whats wrong.

INPUT

/* get input and make pyramid row */
{
   int n;
   do   {
    n = get_int("Height:");
    }
    while (n<1 || n>8);
   
    for (int i=0; i<n; i++)
    
/* align to right - space*/
{  
   for (int j=0; j<n-i; j++)
    {
        printf(" ");
   } 

/* insert # per line */
   for (int k=0; k<=i; k++)
    {
         printf("#");
   }
        printf("\n");
}
}

OUTPUT
$ make mario
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    mario.c  -lcrypt -lcs50 -lm -o mario
$ ./mario
Height:4
    #
   ##
  ###
 ####
$ check50 cs50/problems/2020/x/mario/less
Connecting........
Authenticating......
GitHub username: niha070rika
GitHub password: ************
Preparing...................
Uploading................
Waiting for results...........................
Results for cs50/problems/2020/x/mario/less generated by check50 v3.1.2
:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) rejects a height of 0
:( handles a height of 1 correctly
    expected ""#"", not "" #""
    are you printing an additional character at the beginning of each line?
:( handles a height of 2 correctly
    expected "" #"\n"##"", not ""  #"\n" ##""
    are you printing an additional character at the beginning of each line?
:( handles a height of 8 correctly
    expected ""       #"\n" ...", not ""        #"\n"..."
    are you printing an additional character at the beginning of each line?
:( rejects a height of 9, and then accepts a height of 2
    expected "" #"\n"##"", not ""  #"\n" ##""
    are you printing an additional character at the beginning of each line?
:) rejects a non-numeric height of "foo" 
:) rejects a non-numeric height of "" 
To see the results in your browser go to https://submit.cs50.io/check50/36eda5e409e18b6ef9fa6865ca822543851f70e2
0

check50 is clearly telling you that you are printing an additional space on each line, that is because the for loop indexes that print the spaces are poorly adjusted, you have one more space it should be:

for (int j = 1; j < n - i; j++)
| improve this answer | |

You must log in to answer this question.

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