Contents
How tall do you have to be to play Mario pyramid?
, determines that while the height is less than or equal to 0 OR the height is greater than 23, the program will not exit this loop. This is why entering an input of -1, 0 or 24 for the height makes the program reject those values. Try entering a height of -5 or 100, for example, and those will be rejected too.
How to make Mario pyramids aligned to the right?
Mario (Hash) Pyramid aligned to the right? I need help making the Mario pyramids that are aligned to the right. So far have the pyramids. Check it out. Thanks for your posts. I’m also limited to while, for, and do while etc. loops. – Also comment if you see any syntax errors or see any “bad” style. – How do I reject a non-numeric height?
How is the pyramid formed in CS50 Mario?
So each time it loops round it’s correctly drawing the hashes and a new line but your not telling it to draw any more than 1 space each time as unlike the subloop for the hashes the instruction doesn’t increase with each pass.
Do you have to write Pyramid of spaces upside down?
That is, before your inner for loop, you need another loop for writing these spaces. Note that the pyramid of spaces has to be upside-down. Regarding style, I usually prefer to use do-while loops whenever they fit. As height is initialised to 0, your while loop makes at least one iteration.
How to make a pyramid with height n?
Please help me create the pyramid with height “n” print correctly using hashes and spaces that is right-aligned. I have posted the code itself below. The program correctly asks for the user input, but doesn’t build the pyramid right-aligned. If anyone can fix this, please help.
Why do you print space on the right side of the pyramid?
Because we don’t actually need to print space on the right side of the pyramid. Beside the height variable we need another one that will work as a counter, since we cannot manipulate our height variable. These for loops work in opposite direction, i.e. the more spaces we have, less hashes we print and vice versa.