# Tag Info

2

Don't stress yourself out too much with trying to understand everything, even after reading up on it--sometimes things only "click" after your brain stops thinking about it. Let's take a look at your loops and see if we can't get them to make a little better sense. Instead of looking at all of the code, let's simplify the code down first. Take the ...

2

The problem is in your nested for loop. It prints a space all the way up until i + j <= n - 1. Once this is no longer true, your program exits the loop. Let's look at this in a little more detail: If n = 7 and i = 0, the if statement in the nested loop will continue printing spaces until i + j > n - 1, meaning when j = 7. As soon as that happens, ...

2

if you successfully ran "make mario", why are you running clang? The make command is doing all the compiling and linking for you. Without the correct compiler flags in the command, it won't build. Fortunately, the IDE has those set up by default. If you're trying to "submit" the code for credit, you need to run submit50. Hopefully, you'...

2

Sorry to burst your bubble, but this code doesn't work correctly. It prints a left-justified pyramid. The pyramid is supposed to be right-justified. It prints spaces after the hash marks. They should be printed first. You could replace the space with an x in the print statement to see what's happening. Is it possible you submitted an earlier version of ...

2

Look at this code: int h = get_positive_int("What height do you want: "); //print the pyramid for (int h = 0; h < n; h++) It declares h (as an int) twice. Change one of them. Also, n hasn't been declared before being used. Maybe you meant the first one to be n and not h? There are other issues that you'll discover, but this answers the specific ...

2

Nesting loops to a level of three makes little sense for iterating 2D structures. I think you have to move your innermost loop out, directly in front of the loop it's currently in, so that you have two loops at the same nesting level inside the outer loop.

2

Simply put, the code doesn't compile, so none of the other tests can be done by check50. Did you actually compile your code and run it first, or did you go straight to check50? The code needs to be compiled, tested, and debugged before checking with check50. You need to do this for a number of reasons. The code needs to actually compile, but more ...

2

Here's a hint. How many hashes in the first row? The second row? The third row? Does the number of hashes in any given row have any relationship to the height of the pyramid? Or is the number of hashes related to something else? If that's not enough of a hint, try making a pyramid with no leading spaces. The interesting thing is that most people get ...

1

Please try to understand the pset questions, once you do take small steps and write down problem requirements in word and then transform those into the code exactly as per the specifications. Follow these steps: 1- Prompt the user for the half-pyramid height and print height (You are actually doing it half wrong like using undeclared variable rows and ...

1

The errors are self explanatory. The code accepts 0 as a valid input, it should reject it. In all the pyramids that the code prints, the first line has two #'s. There should be only one. Is it possible that you're working with last year's pset website? It changed this year. If this answers your question, please click on the check mark to accept. ...

1

You assign the height to variable i, and on the next line you overwrite it with 0, throwing away the user input. Make the row counter a different variable, and name your variables according to their meaning, especially if they are used at any point outside of the loop head, and both height and likely also the row counter (or whatever you want to call it) are....

1

Let's have a look at one of those error messages: :( handles a height of 2 correctly expected " ##\n###\n", not "##\n" This means that for a height of 2, the test expected to get: ## ### while the actual output of your program was: ## So your program should print two output lines when height is 2. But if I look into your program loop, I see: for (...

1

cd (change directory) into the directory where mario.c is located (type ls and it should show up), then enter make mario.

1

Don't make things complicated. for x in range (height): print((height-x - 1)*' ' + (x+1)*'#')

1

You make a new file by clicking the green plus sign at the top, next to where it says the name of the file you are currently on. On your keyboard, then do command shift S. It will give you options for where to save the file and what the name should be. Name it pseudocode.txt and put it in your mario folder. If this helps, click the check mark or upvote it.

1

It's a new program. Start with a new file. You're done with hello.c, but feel free to look at it for any ideas on how to do anything you've done in the past. These instructions are guiding you through how to create a new directory to put that file in.

1

You don't have to create a new terminal window, but you should only start mario if you're finished with hello. If you're in the hello directory, on your terminal, execute: cd, cd pset1, mkdir mario, cd mario. Make sure it's in that order. Don't delete your hello.c work though. If this helps, please click the check mark or upvote it.

1

The mario file exists in the mario directory, but you are not executing the command in the same directory. You're in the root directory, two directories above mario.c. You need to be in ~/pset1/mario

1

From the CS50 syllabus: Problems are evaluated along axes of correctness (as determined by a program called check50) and style (as determined by a program called style50), with scores ordinarily computed as 3 × correctness + 1 × style. Since correctness looks to be 100%, verify the style portion with style50.

1

You did use an undeclared identifier j in the second for loop. It isn't created until and only inside the following 3rd for loop. The compiler never lies. It might mislead on occasion, but it never lies.

1

Your code is badly formatted, so it is not possible to reproduce your problem easily. Luckily I know Mario. The range() function starts from zero by default so there are extra lines the solution is to just start from 1: for i in range(1, n + 1):

1

You should write do { printf("height: "); n = get_int(" "); } while (n < 1 || n > 8); instead of do { printf("height: "); n = get_int(" "); } while { (n < 1 || n > 8); } In the do...while loop, the condition is at the bottom of the loop, in parentheses.

1

for (space = 0; space <= height - row; space++) runs height - row + 1 times (+1 for having <= instead of <). For the first row, you should have height - 1 spaces, but you have height + 1. Fix that by having for example space < height - row - 1. Unrelated: height > 0 || height <= 8 makes no sense, is always true. I would not declare ...

1

I don't think you've quite grasped the assignment. The code is to print out the left side of the pyramid so that it is right-justified. That means that it is supposed to have leading spaces before the #s are printed - not just one space on every line. Each line will have one less leading space than the line before. In reviewing your code, I did not see ...

Only top voted, non community-wiki answers of a minimum length are eligible