1

this is for the pset1 problem and my issue is with height = 1 or height 2, can someone please help!

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

int main(void)
{
    int height, lines, spaces, hashes;

    // ask user for height of pyramid
    do
    {
        printf("Height: ");
        height = GetInt();
    }

    // height must be between 1 - 23
    while (height < 0 || height > 23);

    //print lines
    for (lines = 1; lines <= height; lines++)

    {
        //print spaces
        for (spaces = 1; spaces < (height - lines); spaces++)
    {

            printf(" ");
    }

       //print hashes
    for (hashes = 1; hashes < lines; hashes++)
        {
            printf("#");
        }

        printf(" ");

        printf("\n)");

    }

    return 0;
}
0

If height=1, consider how (or if) these lines will be executed:

for (lines = 1; lines <= height; lines++)
for (spaces = 1; spaces < (height - lines); spaces++)
for (spaces = 1; spaces < (height - lines); spaces++)
1
  • Thank you, I finally figured it out :) – Joshua Fraser Aug 24 '16 at 18:38

You must log in to answer this question.

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