I need help with Pset1 Mario

I have been able to print the half pyramid but its backwards (its the right half on the pyramid instead of the left). I believe it must be something to do with my spaces and perhaps not my hash's. I'm not asking for the answer id just like someone to point me in the right direction. I'll only post the 'for loop' parts.

Ive used a do while loop to get the input from the user.

``````    h = GetInt();
x = h;

for  (int i = 0; i <x; i++)
{
for (int i = 1; i < x; i++)
{
printf(" ");
}
for( int i = x; i + 2 >h; i--)
{
print("#");
}
printf("\n";
}
``````

My apologies if its hard to read I couldn't Copy and paste from the CS50 appliance.

• Can you add the code that defines what x and h contain? Otherwise, it's almost impossible to sort out. Jun 23, 2015 at 8:28
• Ive added those. thanks. Jun 23, 2015 at 9:25

The code as written prints the same line each time for the height, and it only has two hashes. The good news is that it will print the first line correctly for any height.

You need to focus on how a given line needs to look - how many spaces and how many #s. There is a relationship between the spaces, the hashes and the number of lines. Try working out on paper how many of each should be printed for a 1 line pyramid, then a two line, and so on. You should be able to figure out formulas for spaces and for hashes based on the height of the pyramid and which line is being printed. That should get you started.

if you follow the logic of your code, you'll find that the first nested loop always iterates `x - 1` times and the second nested loop always iterates 2 times.