I, like several others, have been stuck on pset1 c (mario) for several weeks. Particularly when it comes to printing the spaces and hashes. Could someone help me understand if I'm going about this the right way (sample pseudocode provided below)?

//Create pyramid
for (int hashQuantity = 2; hashQuantity <= height + 1; hashQuantity++)
     //print spaces
     printf (" ") * (height + 1 - hashQuantity); 

     //print hashes
     printf ("#") * hashQuantity;

     //print new line
     printf ("\n");

As you can see, I'm trying to have spaces and the hash character printed out equal to dynamic variables (e.g. "height" and "hashQuantity"). Is this possible/as easy as I think or am I using the wrong format/going about this the wrong way? Thank you for your help.


Interpreting your pseudocode in a way that assuming printf (" ") * (height + 1 - hashQuantity); means iteration(exclusive) over printf(" "),i.e.

for (i = 0 ; i < height + 1 - hashQuantity ; ++i)
     printf(" ");

you are on right track. That works, proceed ahead. Refer to this you still need more help. Best of Luck.

You must log in to answer this question.

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