1

been stuck on this for a couple days, i think i've gotten the spaces concept down, but what am i doing wrong with the #? i know the first row needs 2 #s, so would my for loop begin with hashes=2 ? Appreciate the feedback.

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

int main(void)

{
   int height,spaces,rows,hashes;
do
    {

    printf("give me an integer:");
       height = get_int();

    }
    while (height<=0|| height>=23);

 for (rows=1;rows<=height;rows++)
    {

        for (spaces = height-rows;spaces>=0;spaces--)
             {
                 printf("P");
             }

        for (hashes = 0;hashes<=height;hashes++)

             {
                printf("#");
             }

            {
                printf("\n");
            }



    }

}

2 Answers 2

1

You are on the right track. It may help you to work this out on paper.

To answer your direct question, the problem with your hashes is that you are printing height number of hashes, instead of printing rows number of hashes.

Another tip is that generally speaking, it's better to do:

for (rows=0;rows<height;rows++)

rather than:

for (rows=1;rows<=height;rows++)

But that's not what's causing your problem.

1

Thank you for the help, I finally figured this out. This was probably the most challenging out of all PSET1. On the the next week!

You must log in to answer this question.

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