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

int main(void)
{
int height;
do
{
 printf("Please give an integer that is less than 23 and greater than 0: \n");
 rows = GetInt();
 printf("Height:%i\n", height);
}
while (rows <1 || rows >23);

int i;
int spaces = 22;
int hashes = 2;

{
for(int i = 1; i < rows; i++);
{
    printf(" " * spaces, int);
    printf("#" * hash, int);
    printf("\n");
}

}

I know this question has been asked before but I have been unable to get past the fact that the hashes will not print for me past the first line. I feel like I am close but I am banging my head against a wall. I watched the walkthroughs as well as the pset1 breakdowns but I am still stuck. Any help is appreciated.

  • Whoa that was not the right code. This is it: #include <stdio.h> #include <cs50.h> int main(void) { int height; do { printf("Please give an integer that is less than 23 and greater than 0: \n"); rows = GetInt(); printf("Height:%i\n", height); } while (rows <1 || rows >23); int i; int spaces = 22; int hashes = 2; { for(int i = 1; i < rows; i++); { printf(" " * spaces, int); printf("#" * hash, int); printf("\n"); } } – Constance_DC Jan 6 '17 at 21:09
  • 1
    Please edit your question and replace the incorrect code with the correct code. After changing the code, highlight it and click on the {} curly braces above the entry window to format it as code in the question. – Cliff B Jan 6 '17 at 22:52
  • Kindly please elaborate your question, where are you actually stuck and please use proper way to place code snippets using "{ }" curly braces option to format the code. – Saad Dev. Jan 7 '17 at 10:05
1

Please try to understand the pset questions, once you do take small steps and write down problem requirements in word and then transform those into the code exactly as per the specifications. Follow these steps:

1- Prompt the user for the half-pyramid height and print height (You are actually doing it half wrong like using undeclared variable rows and storing return value of get_int() function in that rows, instead try think to do as follows).

int height;
do
{
    printf("height: ");
    height = GetInt();
}
while (height < 0 || height > 23);

2- Then use height as the condition to the for loop within a for loop to generate the pyramid of #.

Hope it would be helpful for you and always ready for any more help required.

| improve this answer | |
0

@Saad Dev. I got maybe near but with out answers! Can you or anybody tel the name of the function to apply for? Not necessarily write all the code! Thanks!

#include <cs50.h>
#include <stdio.h>    
int main(void)
{
   int height;
do
{
    printf("Height: ");
    height = GetInt();
    for (int i = 1; i < height; i++)
    {
        printf(" ");
        printf("#");
        printf("\n");
    }
}
while (height < 0 || height > 23);
}
| improve this answer | |
  • You need to pull the for loop with the three printf statements out of the do-while loop and put them after it. – Aryaman Jan 8 '17 at 21:53
0

Here a hint

For every you need to print Height - Row - 1 spaces, and 2 + Row hashes

Note : The variable Row is 0-indexed

If this was helpful, please mark as accepted

| improve this answer | |

You must log in to answer this question.

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