#include <stdio.h>
void input(void);
void avgSalary(void);
struct Person{
char name[15];
int age;
float salary;
};
struct Person person[10];
int main(){
int choice, avg;
char cont;
do{
printf("1. Input person record \n2. Average salary\n");
printf("\nPlease enter selection: ");
scanf("%d", &choice);
if (choice == 1){
input();
}
else if (choice == 2){
avgSalary();
}
else{
printf("Error");
};
printf("\nContinue?: ");
scanf("%c", &cont);
printf("\n");
}while(toupper(cont)=='Y');
}
void input(){
int x;
getchar();
for (x=0;x<10;x++){
printf("Person %d\n", x+1);
printf("Name: ");
gets(person[x].name);
printf("Age: ");
scanf("%d", &person[x].age);
printf("Salary: ");
scanf("%f", &person[x].salary);
};
}
void avgSalary(){
int x, sum=0;
float avg=0;
for (x=0;x<10;x++){
sum += person[x].salary;
};
avg = sum/10;
printf("The average salary of %d person is %.2f\n", x, avg);
}
For the output, It asks for person's info and another is the average salary. We select 1 then after entering the first person's name, age and salary, I couldn't enter the next person's name all the way until the 10th person. Why is this happening?