The program intends to accept a character(via a function called menu) from the user and print that character(via the main function). However, when this act of accepting and printing the character is iterated more than once, the program does not accept a second value. Instead, the Return key pressed after entering the first value is registered as the next input.
#include <stdio.h>
char menu();
char menu()
{
char choice;
printf("Menu (Please enter your choice)\nA/a -> Add an employee\nQ/q -> Quit\n");
scanf("%c", &choice);
return choice;
}
int main()
{
char menu_choice;
int i;
for(i=0;i<3;i++)
{
menu_choice = menu();
printf("You've chosen %c\n", menu_choice);
}
printf("End\n");
return 0;
}
The picture shows the output received when the process of accepting and printing a character is iterated thrice using a for loop in the main function.