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

int main (void)
{   int n;
    do 
    {
        printf("Height: ");
        n = GetInt();
        if (n == 0)
        {
            return 0;
        }
    } while (n >23 || n<0);
    int i, j;

    printf("\n");

    for (i = 1; i <=n; i++)
    {   

        for (j = 0; j <n-i; j++)
        {
            printf("%s", " ");
        }

        for (j = 0; j <i; j++)
        {
            printf("#");
        }
       printf("#\n"); 
    }


}

This is frustrating me now because the result is okay everything is okay but the CHECK50 won't accept it even with the spaces and everything, it's very frustrating. Here's the link for the check50: https://sandbox.cs50.net/checks/08aaa3b17d74459aa0e99b9c1aba8172

6
  • what is the error given by check50?
    – abhishek
    Commented Jun 21, 2016 at 17:00
  • link
    – samidha
    Commented Jun 21, 2016 at 17:27
  • Just try removing printf("\n"); placed before that for loop
    – abhishek
    Commented Jun 21, 2016 at 19:43
  • This maybe happening because check50 expects a predefined sequence of outputs. Probably, that "\n" was not a part of it, so it rejects the program, even though the pyramid was correct.
    – abhishek
    Commented Jun 21, 2016 at 20:08
  • @abhishek, please add your comments as an answer. You are exactly correct. By inserting a \n at the beginning of the output, the code is adding extra output. check50 expects exact output, nothing extra, nothing missing. That includes whitespace, linefeeds, prompts, etc. That's why it is failing.
    – Cliff B
    Commented Jun 21, 2016 at 22:24

2 Answers 2

1

Just try removing printf("\n"); placed before that for loop.

This could possibly be happening because check50 expects a predefined sequence of outputs. Probably, that "\n" was not a part of it, so it rejects the program, even though the pyramid was correct.

3
  • THANK YOU SO MUCH! IT FINALLY ACCEPTED I CAN'T TELL YOU HOW HAPPY THAT MAKES ME :D Thanks a ton! :)
    – samidha
    Commented Jun 22, 2016 at 9:03
  • @samidha, welcome, do upvote and click on the 'tick' beside the answer!
    – abhishek
    Commented Jun 22, 2016 at 10:03
  • Thanks and yes, I'll do it! :)
    – samidha
    Commented Jun 22, 2016 at 12:49
-3

Put the printf("\n") outside al of the loops

2
  • Also if that doesn't work look at the zamaylas explanation again try doing it the way she tells you to like first the user's input, then another loop that handles the action, first the spaces then the hashtags.....then a new line etc Commented Jun 21, 2016 at 19:52
  • All printf("\n"); are correctly placed...that is why the pyramid is NOT distorted. (Except that printf() above the for loop, ofcourse)
    – abhishek
    Commented Jun 21, 2016 at 20:03

You must log in to answer this question.

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