I'm trying to get the info and put it into a structure and the structure is an array. I don't have any experience in this. Any help would be greatly appreciated!! The error I get is: error C2664: 'display' : cannot convert parameter 1 from 'struct employee' to 'struct employee []'. It is pointing to case 2 in the main function.
Code:
struct employee {
char name[30];
char ssn[12];
float rate;
float hours;
float gross;
float tax;
float net;
};
#include<stdio.h>
int menu();
struct employee info(void);
void display(struct employee emp[10]);
int main(void)
{
int sel;
struct employee emp[10];
while ((sel = menu()) != -1)
{
switch (sel)
{
case 0: return 0; break;
case 1: emp[10] = info(); break;
case 2: display(emp[10]); break;
default: puts("\a\nInvalid Selection\n");break;
}
}
return 0;
}
struct employee info(void)
{
int num;
struct employee emp[10];
for(num = 0; (num < 10); 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;
return emp[num];
}
}
int menu()
{
int sel;
puts("\nMenu\nPress 1 to input data\nPress 2 to display data\nPress 0 to Quit");
scanf("%d", &sel);
return sel;
}
void display(struct employee emp[10])
{
int choice;
puts("Name SSN Gross Pay Taxes Net");
for ( choice = 0 ; (choice < 10) ; choice++ ) {
printf( "%s %s %f %f %f", emp[choice].name, emp[choice].ssn, emp[choice].gross, emp[choice].tax, emp[choice].net);
}
}