I'm working on the mario staircase right now and everything works so far except printing out the hash symbols correctly. That's the code I've written so far:
int main(void)
{
// declare variable
int height;
// prompt user for number from 0 to 23
do
{
printf("Height: ");
height = get_int();
}
while ( height > 23 || height < 0);
// loop for making the pyramide
for (int row = 1; row <= height; row++)
{
for (int space = (height - row); space > 0; space--)
{
printf(" ");
}
for (int hash = 1; hash <= height + 1; hash++)
{
printf("#");
}
printf("\n");
}
}
Now if I execute mario.c and type for example "Height: 5", that's the output I get:
######
######
######
######
######
I don't understand why the first line prints 5 hashes instead of one. If I code it so that (int hash = 1), shouldn't the first line print only one #, and afterwards add another one because of the hash++?
I would really appreciate it if someone could explain what I did wrong here!