Two problems
1. your input function was caught between inputting a single employee, and inputting all of them. I made it input all
2. your passing array parameters was a little off
Code:
#include<stdio.h>
#define NUM_EMP 10
struct employee {
char name[30];
char ssn[12];
float rate;
float hours;
float gross;
float tax;
float net;
};
int menu();
void info(struct employee emp[NUM_EMP]);
void display(struct employee emp[NUM_EMP]);
int main(void)
{
int sel;
struct employee emp[NUM_EMP];
while ((sel = menu()) != -1)
{
switch (sel)
{
case 0: return 0; break;
case 1: info(emp); break; // pass the whole array
case 2: display(emp); break; // pass the whole array
default: puts("\a\nInvalid Selection\n");break;
}
}
return 0;
}
// instead of trying to return just one employee, it now
// returns all of them
// your for loop suggested that it might
void info(struct employee emp[NUM_EMP])
{
int num;
// use the parameter array instead
// struct employee emp[10];
for(num = 0; (num < NUM_EMP); num++){
printf("Enter employee's name (no spaces): ");
scanf("%s", &emp[num].name);
printf("Enter employee's SSN (999-99-9999): ");
scanf("%s", &emp[num].ssn);
printf("Enter employee's payrate: ");
scanf("%f", &emp[num].rate);
printf("Enter employee's hours worked: ");
scanf("%f", &emp[num].hours);
emp[num].gross = emp[num].hours * emp[num].rate;
emp[num].tax = emp[num].gross * 0.21;
emp[num].net = emp[num].gross * 0.79;
// very bad, you're returning inside your for loop
// return emp[num];
}
}
int menu()
{
int sel;
puts("\nMenu\n"
"Press 1 to input data\n"
"Press 2 to display data\n"
"Press 0 to Quit");
scanf("%d", &sel);
return sel;
}
void display(struct employee emp[NUM_EMP])
{
int choice;
puts("Name SSN Gross Pay Taxes Net");
for ( choice = 0 ; (choice < NUM_EMP) ; choice++ ) {
printf( "%s %s %f %f %f\n",
emp[choice].name, emp[choice].ssn,
emp[choice].gross, emp[choice].tax, emp[choice].net);
}
}