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

void pyramid(int height);

int main(void){
    printf("Height: ");
    int height = get_int();
    if (height < 0 || height > 23) {
        printf("Height: ");
        height = get_int();
    } else if (height==0){
        printf("");
    } else {
        printf("\n");
        pyramid(height);
    }
}

void pyramid(int height){
    int n=1;
    for(int i=0; i<height; i++){

        for(int j=0; j<height-n; j++){
            printf(" ");
        }

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

        printf("  ");

        for(int k=0; k<n; k++){
            printf("#");
        }
        printf("\n");
        n++;
    }
}

I do not have spaces on the right side of the pyramid as far as I know. Here is the check50 link. Why is it telling me that the output is incorrect?

1

Do you have an extra new-line before the pyramid here else { printf("\n"); ?

3
  • Thank you. It's the get_int function that does the new-line, right?
    – Louis
    Jul 24 '17 at 20:50
  • Actually it's when the user hits enter. Jul 24 '17 at 20:54
  • Oooooh. That makes sense. Have a good day!
    – Louis
    Jul 24 '17 at 20:55

You must log in to answer this question.

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