0

I'm stuck on Mario Pset1. I keep receiving line breaks, and the function seems to skip the nested for loops.

#include <stdio.h>
#include <cs50.h>

int check(int b);
int checktwo(int b);

int main(void)
{
printf("What is the height of the pyramid?");
int height = GetInt();
height = check(height);
height = checktwo(height);

for(int rows = 1; rows <= height; rows++)
{
        printf("\n");
        for(int spaces = height - rows; spaces == 0; spaces--)
            {
                printf(" ");
            }
        for(int hashes = rows + 1; hashes == height + 1; hashes++)
            {
                printf("#");
            }

}

}








int check(int b)
 {
    while (b > 24)
    {
    printf("Please input a number less than 24");
    b = GetInt();
    }
return b;
}

int checktwo(int b)
{
    while (b < 0)
{
    printf("Please input a positive number less than 24");
    b = GetInt();
}
return b;
}


// height should be greater than -1 and less than 24
0

For the conditional loops, try "spaces >= 0" and "hashes <= height +1"

0

loop runs only when second for loop parameter evaluates true

Looking at the middle parameter of one of your loops, I see spaces == 0 this indicates your loop will run only when spaces equals 0.

See CS50 Study: Loops for a bit more; basically:

inside the for loop's parenthesis:

  • before first semicolon is evaluated once
  • middle is evaluated each time through and stops if evaluates false
  • third runs after each loop—to keep count, for instance

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .