0

I was banging my head with this. I had to look at others solutions to get my code to work. Here is the code I have, it works now but only because I looked at solution. I had this code written minus the highlighted lines. (if and return). I went over the walk through and shorts and lecture over and over and couldnt find this mentioned. I'm not comfortable moving on until I under stand why these lines are needed.

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

int main(void)
{
    int x = 0;
    do
    {
        printf("Height:");
        x = get_int();

        //Why is this needed?
        if (x == 0)
        {
            //Why is this needed?
            return 0;
        }
    }
    while (x < 1 || x > 23);
    {
        printf("####\n");
    }
}

1 Answer 1

1

This conditional just says that if a height of 0 is entered, which is a requirement of the spec, the program ends by returning 0. If you want to print a pyramid of height 0, you don't actually need to print anything!

You must log in to answer this question.

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