assholenachos assholenachos - 1 month ago 6
C Question

Why doesn't my do while loop work? I put a switch after it and the switch works

It was supposed to get user input but it should prompt the user again for an input if n < 0 and n>23 but all it seems to do when i give it a negative number is it stops working. Here's what it looks like

int n = 0;
do
{
printf("Enter positive height less than 23: ");
n = GetInt();
}
while(n <0 && n>23);
switch(n){
//a list of cases for every number from 0 to 23}


the switch works just fine. My only problem is with the condition in the while.

Answer

try changing your loop condition to

while(n <0 || n>23);
Comments