0

Ok, I have tried and have gotten a 60%. I need at least a 70% to pass. Please. Help. Me. Please. Tell. Me. What. Do. I. Do. I am done cash and now I'm stuck on this! Here is my code:

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

int main(void)
{
    int n;
    do
    {    
        n = get_int("Height: ");
    } 
    while (n <= 0 || n > 8);

    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j < n + i - 1; j++)
        {
            if (i + j >= n)
            printf("#");
        else
            printf(" ");
        }
        printf("\n");    
    }
}

Just help me. I need 10% more. I got 3 out of 5 on correctness and 3 out of 5 on styling. I need 1 more point. AND IM DONE WITH MARIO! I finished cash in like 1 day, and this has taken over a week. Im so pissed!

3 Answers 3

2

I tried running your code in the sandbox, resulting in an additional row without any hashes on top of the pyramid (you can see the space between the pyramid and the height prompt). To solve the problem, the first for loop should have i starting at 1 if you're using <=.

for (int i = 1; i <= n; i++)

Additionally, your second line of hashes have three hashes instead of two. I recommend using another nested loop for the spaces instead of a conditional, so two nested loops inside the first for loop. The number of spaces should be equal to the height n subtracted by the number of hashes.

When it comes to syle, you should check for the code's indentation (in loops or conditionals) as well as adding comments to make your code more easily understood. You can consult the CS50 style guide here: https://cs50.readthedocs.io/style/c/

Good luck and don't give up!

1

You can check your own style by running style50 mario.c

You can see the tests used for grading by clicking the check50 button next to your submission on cs50.me/submissions

With both of those tools, you should be able to figure out where you've gone wrong.

0

In your for loop you are using for (int i = 0; i <= n; i++)

As Justin said if you are going to use i <= n; then you need to start i at 1. However an easier way to do this, although that is correct would to just get rid of the = operator. It's probably good practice to do it this way and makes your code more "readable" for someone who may be looking at your work as well in the future.

You must log in to answer this question.

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