Can someone please help explain what I am missing?

  Kiến thức lập trình

I am taking cs50 and this my first time programming. I thought I understood but I ended up getting a 7/10 on the assignment. We were supposed to prompt the user to give a height input between 1 and 8. Then print an ascending stack of bricks based on that height and right align that stack of bricks. I will paste my code and attach the errors I had. I was hoping someone could explain what I missed to avoid those errors.

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

void print_row(int spaces, int bricks);
int main(void)
{
    // Prompt user for a height value
    int n;
    do
    {
        n = get_int("Enter a height: ");
    }
    while (n < 1 || n > 8);

    for (int i = 0; i < n; i++)
    {
        // Print row of bricks
        print_row(i + 1 , i + 1 );
    }
}

void print_row(int spaces, int bricks)
{
    for (int i = 8; i > spaces; i--)
    {
        printf(" ");
    }

    for (int i = 0; i < bricks; i++)
    {
        printf("#");
    }
    printf("n");
}

enter image description here

New contributor

Tayl74 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

LEAVE A COMMENT