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

int GetHeight();

int main(void)
{
    int a = GetHeight();
    for (int i = a; i < 0; i--)
    {
     for (int j = (i-1); j < 0; j--)
     {
         printf("%s", " ");
     }
     for (int k = 0; k < (a-i+2); k++)
     {
         printf("#");
     }
     printf("\n");
    }
    return 0;
}

int GetHeight()
{
    int n;
    do
    {
        printf("What is the height of your pyramid: ");
        n = GetInt();
    }
    while (n<1 || n>23);
    return n;
}

Hi guys, can anyone help me? I've been stuck with this problem set for some time now and I can't get why this does'nt work. Nothing prints when I run my program other than the reuqest for the height of the pyramind. Appreciate any help. Thanks in advance.

0

Asssuming that a is a positive integer,

 for (int i = a; i < 0; i--)

this loop will never execute. The test condition must be true for the loop to execute. If it is ever false at the start of a loop, execution stops and code continues with the first line of code following the for loop. Maybe you meant i > 0 or something similar? Same problem for the j loop.

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

1
  • Got it, thank you very much!!! Wasn't expecting such a quick reply
    – NaveKom
    Oct 14 '16 at 4:38

You must log in to answer this question.

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