1

My pyramid keeps coming out upside and incomplete. I am not sure what I did wrong but I think it is in my code for the #s. I replaced my spaces with S's to make sure they are there. Can someone help me figure out where i went wrong?

int GetHeight(void);

int main(void)
{
    int n = GetHeight();
    int space,hash;

    for(int i = 0; i < n; i++)
    {
        for(space = n-(i-1); space > 0; space--)
        {
             printf("s");
        }
        for(hash = 4; hash < n + 1; hash++)
        {
            printf("#");
        }
        printf("\n");
    }
}

int GetHeight(void)
{
     int n;
     do
     {
          printf("Height: \n");
          n = GetInt();
     }
     while(n < 0 || n > 23);
     return n;
}
0
1

Why do you run second nested loop unit (n+1) ? I would say run it until (i+2) without any change in the rest of the code, it should work.

for(hash = 0; hash < (i + 2); hash++) // this line is changed
{
        printf("#");
} 

You must log in to answer this question.

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