I'm trying to make a loop in C where the program calculates the avarage of 2 numbers and then waits for user input. If the user input is 'G' then the loop will break. However this is not working currently because it's (in a strange way) a infite loop.
My code is:
while(1){
pogingen++;
gem = (minimum+maximum)/2;
printf("%i",gem);
scanf("%c",&invoer);
if(invoer=='L'){
maximum = gem;
}
if(invoer=='H'){
minimum = gem;
}
if(invoer=='G'){
printf("%i",pogingen);
break;
}
}
I tested it with these values: minimum = 1, maximum = 10. The result will be an infite loop of 5's. It doesn't even wait for the user input (which it's supposed to do.)
Thanks in advance for looking at this!
%c, it would work:scanf(" %c",&invoer);