0

So I've been on Mario for about a week now and I have the user input part and the rows right, and I just need someone to give me tips or how to get started on the spaces and hashes, and btw I really don't want an answer about the pattern because i fully understand the pattern, I just need someone to help me get started, and yes I've watched the video. Here's my code: `int main(void){ int height;

do{   
    printf("Please give a positive integer no more than 23: ");   
    height = GetInt();
}
while(height < 0 || height > 23);

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

    printf("\n");

}

}`

Please help, Neil

  • Ooops the code wasn't properly .. ummm displayed sorry about that – Nilabha Chatterjee Jul 4 '15 at 6:51
2

place 2 "for loops", 1 for spaces and 1 for dashes inside your row "for loop"... tip its a double loop in a loop. your ("\n") needs to be outside your two inner loops. now getting it to work is a different story! but that's a way for it to be done.

| improve this answer | |
6

Well, you wanted some tips, so here are a few thoughts on it. You know that you have to create the correct number of rows, you have that part. Now, you need to think about how to create the spaces and hashes.

Well, break it down into smaller and smaller parts. You need to think about how to build a given row. OK, that's a smaller part. What is a row? It's a series of spaces followed by a series of hashes. So now, you have two smaller chunks to think about - how to print the correct number of spaces on a row and how to print the correct number of hashes on a row.

Now, think about how to do each of those parts as an independant block of code. To get there, think about what a 1 line pyramid looks like, then a 2 line, then 3. Think about the relationships between the number of spaces, the number of hashes, the current line number and the total height. Using all that, figure out which are related and the relationships between them. That will give you the generic formulas.

OK, those are some big hints. If that's not enough, try coding for just the hashes and add the spaces after you get that working. Also, temporarily print 'x' or something else instead of spaces for clarity. It's a lot easier to count characters than spaces!

Lots of hints, pretty much a roadmap. This should get you going!

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

| improve this answer | |
  • Thanks, Cliff B.. I think thats enough to get me starter – Nilabha Chatterjee Jul 4 '15 at 8:33

You must log in to answer this question.

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