I am having trouble getting the pyramid to print anything more than the first row of spaces, and the number of spaces it prints is not correct; for example, for a height of 4, it prints 4 spaces, not 3. It will also not print the hashtags.
Any advice on how to fix these problems would be greatly appreciated. Thank you!
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int h;
int row;
int space;
int hash;
do
{
printf("Height: ");
h = get_int();
}
while (h > 23 || h < 0);
for (row = 0; row < h; row++)
{
for (space = h - 1; space >= 0; space--)
{
printf("-");
}
for (hash = 2; hash <= (row + 1); hash++)
{
printf("#");
}
printf("\n");
}
}
Main
, and I think it is better design to useMain
to simply call those functions. You may also want to consider indenting everything between the first two braces to make your code easier to read.