0

My do while loop for mario.c is not working as expected. This my code:

int height = 0;
do
{
    // make half pyramid
}

while (height < 0 || height > 23)
return height;

When I enter a positive integer > 23, it prints the half pyramid and then re-prompts for height. It works well for non integers, 0, and negatives though. WHATS THE PROBLEM

1

You are asking for it to do that.

Your dowhile reads integer height is smaller than 0 or larger than 23.

If I remember correctly, such a dowhile function was used with GetInt() in the class, and that was because you wanted to prompt for a number again, and not print a pyramid if the user did not give a value between 0 and 23. You can validate the user input and ask them again in this manner, but you are going to probably use another kind of loop to print the pyramid out.

| improve this answer | |
  • Thanks. I nested a dowhile loop for getting the height and it works well. – azbaako Feb 24 '15 at 22:33

You must log in to answer this question.

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