The following is my code for PSET1 Mario.c where the expected outcome is the user is prompted for a height number between 1-23, and based on that number, it builds a half pyramid with the "#" symbol. However, my code repeatedly asks for the Height instead of printing anything. Any hints/suggestions where I went wrong? Thank you in advance!



1 Answer 1


The do/while loop will execute as long as height >= 0 || height <= 23 is true. Since it's an or condition, it is true if either is true. Every integer will return true, because every integer is either >= 0 or <= 23. Think of the while loop in terms of the inputs you want to reject. Once you have a valid input, don't do the loop any more.

  • Wow, thank you! That makes sense now. Now it prints, but infinitely. At least it is a step forward to finding the solution :-) Must be my for loops now. Commented Feb 22, 2017 at 0:54

You must log in to answer this question.

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