I am having issues tackling the corner cases for Mario (e.g. height < 0 or height > 23). I'm assuming you prompt the user to keep entering an integer in a while loop until he/she has entered an integer within the bounds defined. However, I keep getting an infinite loop in my code as shown below:

printf("Please enter the half-pyramid's height:\n");
    printf("Height: \n");
    int height = GetInt();

while (height < 0 || height > 23);
  • I would call this an "edge" case, because it's at the max/min of only a single variable and it's relatively likely to occur. "Corner" cases exist at the extremes of two or more variables (e.g., at the corner of an x-y grid) and as a result tend to be exponentially more rare. It's not uncommon for people to use "corner" case to describe situations that aren't even worth the time to deal with because they are so unlikely. Just FYI - some more discussion here. :)
    – Air
    Jul 30, 2014 at 17:37
  • Thanks for the clarification! Jul 30, 2014 at 22:06

1 Answer 1


You've declared your integer height inside the curly braces, so it is no longer in scope (no longer in existence) once you reach the end of the curly brace. I'm assuming you've also declared it before this bit of code you are showing, and it will be that height that is being compared.

Inside the do, simply set the height without declaring it again.

  • I changed it up a bit, but I'm still running into some issues. When I enter a valid integer, the program still goes through the while loop and prints whatever's inside it. Jul 29, 2014 at 23:37
  • Here's the code for reference: printf("Please enter the half-pyramid's height: "); int height = GetInt(); while (height < 0 || height > 23) { printf("Height: "); height = GetInt(); } Jul 29, 2014 at 23:37
  • Your initial code was fine. The only problem was that you were declaring int height inside the loop when you only needed to set it height = getInt();
    – curiouskiwi
    Jul 30, 2014 at 0:01
  • Made the appropriate fix and it worked. Thanks :). Jul 30, 2014 at 0:05

You must log in to answer this question.

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