I have two do/while loops in my program. One is stopping as expected and waiting for a reply from the keyboard input. In the second, it runs through the loop twice each time and I can't figure out why. Here is the code for the failing loop.
Code:
}else{
char result = ' ';
do{
randnum = genRandNum(lower,upper); //generating random number between range
printf ("I will now guess a number between %d and %d, which is: %d.\n", lower, upper, randnum);
printf ("Is my guess (c)orrect, (l)ow, or (h)igh?\n");
scanf ("%c", &result);
guesscount++;
if (result =='l'){
if (randnum > lower && randnum < upper){ //making sure lower range limit should be changed
lower = randnum;
}
}else{
if (result == 'h'){
if (randnum > lower && randnum < upper){ //making sure upper range limit should be changed
upper = randnum;
}
}else{
printf ("Great, I got it right in %d guesses.\n",guesscount);
}
}
}while (result != 'c');