Greetings,
I've been tasked to create a menu driven program that accepts various inputs from the user and displays the data back to them. Relatively simple I'm sure but I'm having a problem with fgets not pausing for a string entry.
Here is the code I've written so far:
Code:
void perform_menu_tasks( int e ) {
if( e == 1 ) {
printf("Enter the opponent's name: ");
fgets( user_input.opp_name, sizeof (user_input.opp_name), stdin );
// Code will be entered here to remove newline character.
}
else if( e == 2 ) {
printf("Enter USC's points: ");
scanf("%d", &user_input.usc_points);
}
else if( e == 3) {
printf("Enter opponent's points: ");
scanf("%d", &user_input.opp_points);
}
else if( e == 4) {
printf("Enter Half-Time fans: ");
scanf("%d", &user_input.ht_fans);
}
else if( e == 5) {
printf("Enter number of parolees: ");
scanf("%d", &user_input.parolees);
}
else if( e == 6) {
printf("Enter amount of payments: ");
scanf("%f", &user_input.payments);
}
else if( e == 7) {
printf("Enter number of visor tosses: ");
scanf("%d", &user_input.visor_tosses);
}
else if( e == 8 ) {
printf("\n\nOpponent: %s\n", user_input.opp_name);
printf("USC's points: %d\n", user_input.usc_points);
printf("Opponent's points: %d\n", user_input.opp_points);
printf("Half-time fans: %d\n", user_input.ht_fans);
printf("Number of parolees: %d\n", user_input.parolees);
printf("Amount of payments: %.2f\n", user_input.payments);
printf("Number of visor tosses: %d\n\n\n", user_input.visor_tosses);
}
else if( e == 9 ) {
user_input.usc_points = 0;
user_input.opp_points = 0;
user_input.ht_fans = 0;
user_input.parolees = 0;
user_input.payments = 0;
user_input.visor_tosses = 0;
}
}
Menu choices 2-10 are working with no problems, but when the user chooses 1, there is no pause for the user to enter a name, it only reprints the menu. If anyone could analyze my code with any hints I would be forever grateful.
Thanks.