CS50 Problem Set 1 Mario Less

I’m sure you have stumbled across this before but I have perused through the issues and can’t seem to fine someone stuck specifically where I am.

Currently I have everything scripted to allow for user input greater than 0 and less than 8 as required. The pyramid structure is created but I cannot get it to build from right to left. I have tried multiple nested loop layouts and always get a similar structure to this:
(# )
(# #)
(# # #) *ignore the parenthesis as they are only there to eliminate the tag formatting.

Where the spaces are added in between each hash instead of compiled as a group prior.

Here is my code:

void print_blocks(int length);

int main(void)
{
    int height;
    do
    {
        height = get_int("Height: "); //prompts user input of integer
    }
    while (height < 1 || height > 8);

    for (int i = 0; i < height; i++) //loops through to print the rows
    {
        print_blocks(i + 1); //calls the input value
    }

}


void print_blocks(int length) //function to print # on row's
{
    for (int i = length + 1; i > length; i--)
    {
        for (int l = 0; l < length; l++)
        {
            printf("#");
        }
        printf(" ");
    }
    printf("\n");
}

Could you give some examples - what is the expected result, what happens instead?

For sure! So currently I have a left correlated Pyramid when I run the code is loops through printing like this:
(#)
(##)
(###)
(####)
(#####)

What I need is it to flip, so I am trying to, in essence, add spaces to the front of the pyramid that counts the opposite of the #'s so it’ll print with the top block being far right instead of far left and correlate accordingly. Kinda like a word document that aligns right, if that makes sense.

Writing it by hand on paper, how would you do that? Then, how that can be imitated when writing something on computer?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.