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

int main(void)
{   
    int height,i,j;
    printf("Enter a non-negative integer < 24: ");
    height=get_int();
    while( height<0||height>23 )
    {
        printf("Enter a non-negative integer < 24: ");
        height=get_int();
    }
    for(i=0;i<height;i++)
    {
        for(j=0;j<height-i-1;j++)
        {
            printf(" ");
        }
        for(j=0;j<=i;j++)
        {
            printf("#");
        }
        printf("  ");
        for(int k=0;k<=i;k++)
        {
            printf("#");
        }
        for(int k=0;k<height-i-1;k++)
        {
            printf(" ");
        }
        printf("\n");
    }
2

You don't need to print trailing spaces at the end of the line. Check50 looks for a very specific output and it doesn't expect to see extraneous spaces.

As a style note by the way, you shouldn't progressively indent for loops nested within a master for loop. You should only increase the indent each time you nest i.e.:

for (a)
{
    for (b)
    {
    }
    for (c)
    {
    }
    for (d)
    {
    }
}
-1

Your program prompting user with printf("Enter a non-negative integer < 24: "); and in the pset1 description for mario, it is specifically said to prompt user with Height:.

check50 is very specific while checking your output to their answers. They even check whether your pointer is after Height: or at new line. So, Don't use \n after printing user prompt of Height:. But they don't check for the spaces in your code, it checks only output..

Everything else seems fine to me..

You must log in to answer this question.

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