0

So far I am able to get input from user and print the amount of rows using a loop, but after that i am stuck.

after this, i just don't know how to approach adding an extra # starting on row 2 and also how to add spaces to make the top rows shift to the right.

Please point me in the right direction and how to think about this problem.

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

int main (void)
{

int height;

do 
{
    printf("Height: ");
    height = get_int();
}
while (height < 0 || height > 23);


for (int rows = 0; rows < height; rows++) 
{

    printf("##");

    printf("\n");

}


}
2
  • Have you seen the walkthrough? (See this link: docs.cs50.net/problems/mario/less/mario.html#walkthrough) It might help you identify some of the problems. You should also check out the hint: Try to establish a relationship between (a) the height the user would like the pyramid to be, (b) what row is currently being printed, and (c) how many spaces and how many hashes are in that row. Once you establish the formula, you can translate that to C! – SuperNovaCoder Apr 24 '17 at 0:15
  • Also, why do you just print two hashes per row? Each row needs a different amount of hashes as well as the proper amount of spaces. You can review the staff's solution to see the proper output. You can then compare this to your output and gather an idea of what you should do. – SuperNovaCoder Apr 24 '17 at 0:17

You must log in to answer this question.

Browse other questions tagged .