0

I have been trying to fix the whitespace error generated with my code:

int main()
{
    int height;
    do
    {
        printf("Height: ");
        height = get_int();
    } while (height < 0 || height > 23);

    for (int i = 0; i <= height; i++)
    {
        int x = height - i;
        if (x != height)
        {
        printf("%.*s", x, "                       ");
        printf("%.*s", i, "#######################");
        printf("  ");
        printf("%.*s", i, "#######################");
        printf("\n");
        }
    }

    return 0;
}

I understand that check50 requires a newline after the last # in each line. That was the purpose behind

printf("\n");

on line 22, which runs once per printed line. However this doesn't solve the problem, and only when height = 23 does the last line have no trailing whitespace. Any help is appreciated.

3
  • the program passed check50 for me .... ?? – MARS Nov 7 '17 at 19:23
  • @MARS for me I had ':( handles a height of 2 correctly', ':( handles a height of 23 correctly', ':( rejects a height of 24, and then accepts a height of 2' – Trawkley Nov 7 '17 at 19:27
  • It's now working. – Trawkley Nov 7 '17 at 19:51

You must log in to answer this question.

Browse other questions tagged .