0

Could any one please tell me what's the "styling problem" in this code? I keep getting score of 4 out of 5 and I don't understand what I miss ?

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

int main(void)
{
    // Ask player for height    
    int height = get_int("Height: ");
    // Check that height is less than 1 or greater than 8
    while (height < 1 || height > 8) 
    {
        height = get_int("Height: ");
    }
    // build Pyramid
    for (int i = 1; i <= height; i++)
    {
        // loop adding spaces
        for (int w = height-i; w > 0 ; w--)
        {
            printf(" ");
        }
        // loop adding hashes
        for (int j = 0; j < i; j++)
        {
            printf("#");
        }
        // add new line after each iteration
        printf("\n");
    }       
}
3
  • What does style50 mario.c say?
    – Blauelf
    Apr 2 '19 at 21:06
  • OHH.. I just started the course.. and I didn't know about that function, I used it and found the error.. thanks Apr 3 '19 at 3:42
  • They introduce the tool later, to not confuse people with too many tools at once. You need only 70% to pass a problem, and can resubmit as you want, so the 4/5 most people get on style has no negative effect (other than hurting you in your completionism).
    – Blauelf
    Apr 3 '19 at 6:37
0

There's a tool called style50 to check the style, it's introduced later in the course.

From just looking at the code, I'd guess the line

        for (int w = height-i; w > 0 ; w--)

should be

        for (int w = height - i; w > 0; w--)

(adding two spaces, removing one).

You must log in to answer this question.

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