0

Testing the code manually, the output seems ok. But then when I use check50 it fails with the inputs 2 and 23.

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

int main(void)
{
    printf("Type the half-pyramid's heigths (between 1-23): ");
    int height = get_int();

    if (height < 0 || height > 23){
        printf("\nThe maximum value must be 23.\nPlease type again: ");
        height = get_int();
    }

for (int i = 0; i < height; i++){
    int hash = 0, space = 0;
    int s = (height - i - 1);
    while (space < s){
        printf(" ");
        space++;
    }
    while (hash <= i){
        printf("#");
        hash++;
    }
    printf("  ");
    hash = 0, space = 0;
    while (hash <= i){
        printf("#");
        hash++;
    }
    while (space < s){
        printf(" ");
        space++;
    }
    printf("\n");
}

}

Can anyone tell me what am I doing wrong?

0

1 Answer 1

0

Use while, not if for rejecting wrong height values, or you always accept the second input.

You problem are the trailing spaces, the checker does not like them, while you won't see the difference.

3
  • Made the change with the while. But did not get what is wrong with the trailing spaces... Commented Mar 8, 2017 at 19:52
  • The checker does not expect any spaces at the end of the line, that's it.
    – Blauelf
    Commented Mar 9, 2017 at 5:36
  • Done. Thank you very much! Commented Mar 13, 2017 at 5:33

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