0

The instructions are here: http://cdn.cs50.net/2016/x/psets/1/hacker1/hacker1.html#itsa_mario

and here for the full understanding of the basic requirements:

http://cdn.cs50.net/2016/x/psets/1/pset1/pset1.html#itsa_mario

The problem is I get the correct output but my code isnt correct.

Check50:

:) mario.c exists

:) mario.c compiles

:) rejects a height of -1

:) handles a height of 0 correctly

:) handles a height of 1 correctly

:( handles a height of 2 correctly
   \ expected output, but not " #  # \n##  ##\n"

:( handles a height of 23 correctly
   \ expected output, but not "                      #  #             ..."

:) rejects a height of 24

:) rejects a non-numeric height of "foo"

:) rejects a non-numeric height of ""

MY OUTPUTS My OUtputs

CS50 OUTPUTS Outputs of CS50 Staff implementation

Finally, my code:

{
     int height;
     int i;
     int spaces1;
     int blocks1;
     int spaces2;
     int blocks2;


     do 
     {
        printf("Height: ");
        height = GetInt();
         if (height==0)
         {
             return 0;
         }

     }
     while 
     (height < 0 || height > 23);

    if (height == 1)
    {
        for (i=0; i<1;i++)
        {
            for (blocks1 = 0; blocks1 < 1; blocks1++)
            {
                printf("#"); 
            }

            printf("  ");

            for (blocks2 = 0; blocks2 < 1; blocks2++)
            {
               printf("#");   
            }

            printf("\n");
        }
    }



    else  
    {
        for (int a=1; a<height +1; a++)
        {
            for(spaces1 = 0; spaces1 < height-a; spaces1++)
            {
                printf(" ");
            }

            for (blocks1 = 0; blocks1 < a; blocks1++)
            {
                printf("#"); 
            }

            printf("  ");

            for (blocks2 = 0; blocks2 < a; blocks2++)
            {
               printf("#");   
            }

            for(spaces2 = 0; spaces2 < height - a; spaces2++)
            {
                printf(" ");
            }

            printf("\n");
        }

    }




}

Thanks a lot.

0
1

I had the exact same issue. The output looks correct but it is not. Just ask yourself if you really need what you called "spaces2"

0

The error seems to be only with height of 2 and 23.

For that try this

for(int j=0; j<height-i; j++){
            printf(" ");
        }
        for(int k=0; k<i; k++){
            printf("#");
        }
        printf("  ");
        for(int k=0; k<i; k++){
            printf("#");
        }
        for(int j=0; j<height-i; j++){
            printf(" ");
        }
        printf("\n");
}

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