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


int main(void)
{
    int block;

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

    // printf("You have selected to create %i blocks\n", block);

    for (int height = 0; height < block; height++)
    {

         for (int spaces =  0; spaces < block-height-1; spaces++)
        {
            printf(" ");

        }

        for (int hashes = 0; hashes < height +1; hashes ++)
        {
            printf("#");
        }

        printf(" ");

        for (int hashes2 = 0; hashes2 < height +1; hashes2 ++)
        {
            printf("#");
        }

    printf("\n");
    }



}

Hi everyone, this is my code and during the test it outputs what I believe is the same as what check50 is meant to be checking for.

The error I get is:

:( handles a height of 1 correctly
    expected "# #\n", not "# #\n"
:( handles a height of 2 correctly
    expected " # #\n## ##\n", not " # #\n## ##\n"
:( handles a height of 23 correctly
    expected " ...", not " ..."
:( rejects a height of 24, and then accepts a height of 2
    expected " # #\n## ##\n", not " # #\n## ##\n"

From the search I've done on stackexchange it seems that previous users with the same error either had a space on the right hand pyramid or there is a double space in between the two pyramids. I feel that my code does avoid both of the problems.

Can someone please explain to me what the error is trying to point out as it seems my code matches the check.

Thanks

Alex

3

If I remember correctly, there should be two spaces between the half-pyramids.

If the output is not put into an HTML pre tag, any contiguous whitespace will be compacted into one space, that's why you probably don't see anything in the check50 output.

| improve this answer | |
  • Check50 is only showing one space when output is returned in the terminal window too. It should show two spaces. I've passed this along to get both command window and web page output fixed. (Also, remember this is pset1, not the later pset.) – Cliff B Nov 5 '17 at 21:14
  • Wasn't aware check50 did the same thing. Doesn't help with diagnosing the mistake then. – Blauelf Nov 6 '17 at 7:38
  • Thank you, you were absolutely right. I misread the instructions but check50 threw me off :) – Alex Nov 6 '17 at 11:08
  • This bug should be reported. – Ankur Parihar Feb 15 '18 at 20:45
1

The problem is simple. There are supposed to be TWO spaces between the left and right sides of the pyramid.

It's only partly your fault that you couldn't figure it out. The output from check50 seems to indicate that there's only supposed to be one space, while the pset spec says two. I'll pass a request on to fix this.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • The issue is already being investigated. Should see it fixed soon. How's that for fast response?! ;-) – Cliff B Nov 5 '17 at 21:19
  • Thank you for the response, reading is an important skill it seems :) It has been fixed as per your answer. – Alex Nov 6 '17 at 11:07

You must log in to answer this question.

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