1
    // get height of pyramid from user
    printf("height: ");
    n = GetInt();
}

// printing output for pyramid
if (n > 0 && n <= 23)
{

    for (int i = 0; i < n; i++)
    {

        // print space
        for (int x = 0; x < (n - (i+1)); x++)
        {
            printf(" ");
        }

        // print hashes
        for (int y = 0; y <= (i + 1); y++)
        {
            printf("#");
        }

        printf("\n");
    }
}

// return zero when imputs is 0
else if (n == 0) 
{
    return 0;
}

// prompt user to retry when input is not within 0 and 24

else
{
    do
    {
        printf("Retry: ");
        n = GetInt();
    }    
    while (n < 0 || n > 23);
}
1

Your code will return 0 because you reach the end of the program.

Remember, it runs in order. Your pseudocode as you've shown:

   get height from user

   if it's a valid height
       print the pyramid
   else if the height is zero
       end the program
   else 
      ask for a new height and keep asking if wrong

   **end**

If you want it to do something after you ask for the new height, you'll have to ask before you print the pyramid. Maybe a do while loop should come first instead of at the end.

That should be enough hints to get you back on track.

You must log in to answer this question.

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