0

I've typed make less in the terminal but nothing happens. Here's my code:

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

int main(void)
{
    // Ask user for height
    int height;
    do
    {
        height = get_int("Height: ");
    }
    while (height < 0 || height > 23);

    // Print mario pyramid
    for (int i = 0; i < height; i++)
    {
        for (int space = height - 1; space == 0; space--)
        {
            printf(" ");
        }
            int space = height - 1;
            for (int hash = height + 1 - space; hash == height - 1; hash++)
            {
                printf("#");
            }
    printf("\n");
    }
}



While trying to understand my code through python tutor, I realised that my variable space remains 3 forever, but I can't figure out how to fix my for loop at line 11.

pset 1 - mario less

1

Did you save the source code in a file called "less.c"? It's supposed to be saved in a file called "mario.c". Then, once saved, run the command make mario Also, be sure that you're in the same directory as the mario.c file to compile it.

Having compiled, there's also the issue of the for loop. The condition clause must be true for the loop to execute. space == 0 is false at the start of the run, so the loop never executes. You need to change the condition to something that's true until space == 0. I'll let you figure that one out. ;-)

Finally, the first 5 psets are written in c. There are differences between c and python, so be aware that you need to write to the c standards. Python comes later. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • Thanks for pointing out my file name as well as explaining the condition clause! :) Just to clarify, python tutor is used to visualise many languages, including Python, C, Java etc.
    – Michelle
    Jun 14 '18 at 2:14
  • Noted. Most IDEs will do that, but I just wanted to make sure. ;-)
    – Cliff B
    Jun 14 '18 at 3:10

You must log in to answer this question.

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