0 down vote
I wonder if someone can clear something up for me. I have been working on this problem, and I have got a solution that works. ie, the numbes of spaces decline, and the number of hashes increases. BUT. I don't understand why it works.
This is part of the code. Height is the integer number given by the user. I then defined an integer s, equaled it to 'line' (has to be line otherwise the program doesn't work,
I initially tried this logic: the number of spaces has to be (height - 1) to start off with, and from there on, each line has one space less, so I tried to place s-- in the 'for loop'. But it didn't work.
What I did was the following, which works perfectly, but the logic seems all wrong to me. It shouldn't work, but it does. Nowhere am I stating I'm decrementing s, so why does the program do it?
for (line = 0; line < height; line++){
// print the spaces --> how on earth does this work??? Shouldn't this see
//the spaces increasing? Not decreasing?
for (s = line; s < height - 1 ; s++){
printf(" ");
}
}
Hope someone can shed some light on this. Many thanks
printf("#");
statement anywhere.