0

I'm totally new at programming. and i'm stuck at making mario, so i've searched a lot. I've got an idea from the other questions and made a code, but it looks quite funny. Here's my code.

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

int main(void)
{
    printf("Height: ");
    int height = get_int();
    if (height >= 24 || height < 0 )
    {
        printf("retry\n");
    }
    else
    {
        for (int i = 0; i < height; i++)
        {
             for (int j = 0; j < i; j++)
             {
                 printf(" ");
             }
             for (int k = i; k < height; k++)
             {
                 printf("#");
             }
             printf(-"  ");
             for (int k = i; k < height; k++)
             {
                 printf("#");
             }
             printf("\n");
        }
    }
}

My code makes up-side-down mario structure. Could you guys give me a hint to change this side up to down? Maybe my english is not so good but please help me.

1

The code could be corrected, but at this stage in learning to program, I would suggest starting over on the main loop section of the code so that you don't get bogged down in confusion. Instead, work from a plan. Work on one small part at a time, get it right, and then add another part.

Since you have the data entry part right, move on to building the pyramid. Start with the hash marks for the left half of the pyramid. Get the program to print the correct number of hash marks on each line. Forget about the leading spaces for now and just get the number of hashes for the left half of the pyramid right.

Once you get that right, then add the leading spaces. Once you have this, you have the complete left half of the pyramid done.

Finally, add the middle spaces and the right side hashes. This should be easy because you will have all the code needed to do the job.

It's that simple. Just build one part at a time until all the pieces are there.

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

| improve this answer | |

You must log in to answer this question.

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