Stuck on Pset 1 - drawing the pyramid (prompting the user for a number between 0 and 23 working fine).
When I try to execute this program, it goes crazy- is there something wrong with my for loops?
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
spaces-- will decrement
spaces < height - row - 1 will stay true until the integer does an overflow (going from least possible value to highest possible value by subtraction of one).
You probably meant
Usually, if you don't care for the exact value of the counter (or one of these happens to be fine for you), you'd pick your loop either as
for (int counter = 0; counter < repetitions; counter++)
for (int counter = repetitions; counter > 0; counter--)
as both clearly show the number of repetitions.
The comparison operator should match the direction of the counter.