0

So i've spent way too much time on this. Didnt expect it to be so difficult. I think i got the coding right but for some reason the program is only executing till the do-while loop and then it exits after getting a positive integer within the condition.

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

int main(void)
{
    int height;
    int spaces;
    int hashes;
    do
    {
        height = get_int("Height: ");
    }

    while (height < 0 || height > 23);
    for (int i = 1; i <= height; i++)
    {
        for (spaces = (height - i); spaces > 0; spaces--)
        {
            printf(" ");
        }
        for (hashes = 1; hashes <= (i + 1); hashes++)
        {
            printf("#");
        }
        printf("\n");
    }
    return 0;
}

And this is the output i get. Please help, why is the program not executing my for loops? enter image description here

  • Are you sure this output is from the source you posted? Have you run make mario successfully in between? – Blauelf May 22 '19 at 9:57
  • What Blauelf said. You must save the source code file after making changes and you must remake the executable after changing the code. – Cliff B May 22 '19 at 11:10

You must log in to answer this question.

Browse other questions tagged .