I have a problem in the followring code. After collecting the information for 3 employees, the program displays 2. Why?
"The program should loop around the user prompts three times to read the information for three entries in the employee_database"
#include <stdio.h>
/* first define a single record */
typedef struct {
char forename[10];
char surname[10];
int age;
float salary;
} record_template;
/* now to create the array if records*/
int main()
{
record_template employee_database[20];
int t;
int counter;
for (t=0; t<3; t++)
{
printf("Enter your forename\n");
scanf("%s",&employee_database[t].forename);
printf("Enter surname\n");
scanf("%s", &employee_database[t].surname);
printf("Enter age: ");
scanf("%d", &employee_database[t].age);
printf("Enter salary: ");
scanf("%f", &employee_database[t].salary);
}
for (counter=0; counter <3 ; counter++)
{
printf("\n\n");
printf("Employee no. %d\n", counter);
printf("Surname: %s\n", employee_database[counter].surname);
printf("Age : %d years \n", employee_database[counter].age);
}
}
thanks a lot