So I'm fairly sure I have everything in the correct order, it compiles correctly, but when I try to run I just crash after the first Employee ID input. I've tried all i can think and have searched the web yet can't figure out why it crashes.
#include <stdio.h>
#include <string.h>
struct Employee
{
int ID;
char fName[51], lName[51];
float pay;
};
int main()
{
struct Employee eArray[5];
int i,j,k,a,search,idSearch,paySearch;
char lSearch[51];
for(i=0;i<5;i++)
{
printf("Enter ID number for employee %d:", (i+1));
scanf("%d", eArray[i].ID);
for(j=(i+1);j<5;j++)
{
if(eArray[i].ID == eArray[j].ID)
{
printf("Duplicate ID number, enter again:");
scanf("%d", eArray[i].ID);
}
}
for(k=(i-1);k<i;k--)
{
if(eArray[i].ID == eArray[k].ID)
{
printf("Duplicate ID number, enter again:");
scanf("%d", eArray[i].ID);
}
}
printf("Enter first name for employee %d:", (i+1));
gets(eArray[i].fName);
printf("Enter last name for employee %d:", (i+1));
gets(eArray[i].lName);
printf("Enter hourly pay for employee %d:", (i+1));
scanf("%f", eArray[i].pay);
}
printf("Search for employee by Last Name(1), ID(2), Hourly Pay(3):");
scanf("%d", &search);
if(search==1)
{
printf("Please enter Last Name to search for:");
gets(lSearch);
for(a=0;a<5;a++)
{
if(strcmp(eArray[a].lName, lSearch)==0)
{
printf("%s %s\nID:%d\n$/hr:%f\n", eArray[a].fName, eArray[a].lName, eArray[a].ID, eArray[a].pay);
}
}
}
else if(search==2)
{
printf("Please enter ID to search for:");
scanf("%d", &idSearch);
for(a=0;a<5;a++)
{
if(eArray[a].ID==idSearch)
{
printf("%s %s\nID:%d\n$/hr:%f\n", eArray[a].fName, eArray[a].lName, eArray[a].ID, eArray[a].pay);
}
}
}
else if(search==3)
{
printf("Please enter Hourly Pay to search for:");
scanf("%d", &paySearch);
for(a=0;a<5;a++)
{
if(eArray[a].pay==paySearch)
{
printf("%s %s\nID:%d\n$/hr:%f\n", eArray[a].fName, eArray[a].lName, eArray[a].ID, eArray[a].pay);
}
}
}
return 0;
}