Having a little issue understanding this. in the mario code I'm looking at.
// I understand this repeats the loop "pyramid_height" times. all good here.
for(int i = 0; i < pyramid_height; i++)
// here's my question. this will print appropriate number of spaces. Say a pyramid height of 5 -i (say were on the 3rd row so "i" would equal 3 correct?) -1 To me this looks like 5-3-1=1 that would print one space..but I would want to print 2 spaces on the third row.
{ for(int j = 0; j < pyramid_height-i-1; j++) { printf("%s", " ");
FULL CODE BELOW
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int pyramid_height = 0;
do {
printf("Height:");
pyramid_height = GetInt();
if (pyramid_height == 0)
{
return 0;
}
} while (pyramid_height < 1 || pyramid_height > 23);
for(int i = 0; i < pyramid_height; i++)
{
for(int j = 0; j < pyramid_height-i-1; j++)
{
printf("%s", " ");
}
for(int k = 0; k < i+2; k++)
{
printf("#");
}
printf("\n");
}
return 0;