The program takes two inputs and if the result is N then it goes through the while loop until the user types N five times. If Y is pressed then it exits the loop.
This while loop executes perfectly if the input is Y, however, if the input is N, it executes properly the first time it runs but the second time it executes line 13 twice before moving on. It seems to miss getting an input the second time, but then it fixes after returning, thus the result is shown as:
Here is my code:
// Preprocessor commands
#include <stdio.h>
#include <stdlib.h>
//-----------------------------
int main(){
int attempts=0;
char result;
while(attempts < 5){
printf("\n");
printf("Entered Loop\n");
printf("Enter result (P/F)\n");
scanf("%c", &result);
if(result == 'P'){
printf("Passed\n");
attempts++;
break;
}
else if(result == 'F'){
printf("Entered F Loop\n");
printf("Try again\n");
attempts++;
continue;
}
printf("Exited F Loop\n");
}
if(attempts == 5){
printf("QUIT!\n");
}
}