0

I am testing the first part of my code for Mario, pset1. I am using a do while loop because I thought the 'while' will return to the 'do' part if you put in a invalid number. But when I use the terminal and I put in an invalid number it's not asking me the same question again. I get exactly the same reaction when I put in a valid number. What am I doing wrong?

int main(void) { // Here we ask for the hight of the halfpyramid. int hight;

do
{
printf("Give a number for the hight of the pyramid: ");
hight = GetInt();
}
while (hight < 0 && hight > 23);
1

Look at the test in the while loop:

while (hight < 0 && hight > 23);

The while loop will repeat when the test condition is true. So with that in mind, can you tell me any number that can be less than zero AND greater than 23 at the same time?

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

| improve this answer | |
  • Ok, good point, so I change it into or (||)! Thank you very much! – LvdD Sep 26 '15 at 19:15

You must log in to answer this question.

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