EDIT: UPDATED CODE BELOW
#include <stdio.h>
#include <cs50.h>
int main(void)
{
printf("How tall is the pyramid?: ");
int pyramidHeight = GetInt(); //get height of pyramid from user
while(pyramidHeight <= 0 || pyramidHeight > 23) //if the user inputs a number less than or equal to 0 or greater than 23, prompt for a number again
{
printf("Please enter a number between 1 and 23: ");
pyramidHeight = GetInt();
}
int space = pyramidHeight - 1; //initial amount of spaces to print
int hash = 2; //initial amount of hashes to print
for(int currentHeight = 0; currentHeight != pyramidHeight; currentHeight++) //while current pyramid height is less than final height
{
for(int spaceCurrent = space; spaceCurrent != 0; spaceCurrent--) //spaceCurrent = number of spaces currently being printed
{
printf(" ");
}
space--; //print one less space next time
for(int hashCurrent = 0; hash != hashCurrent; hashCurrent++) //hashCurrent = number of hashes currently being printed
{
printf("#");
}
hash++; //print one more hash next time
printf("\n"); // move to next line
}
}