I have to write a program to calculate 10 employees gross pay, deductions, net pay, and include overtime if applicable. I must use a structure to do this and the name can be a max of 20 characters and the ID is 6 characters. I know my main problem is how I am using array in my structure as I had this working fine with only one employee. Maybe I am just not understanding how to properly implement them into the structure. I have tried nesting it with another structure and that included my name [21] and pin[7] and doing it more as a string, and a few other things that sounded viable in my head but nothing has worked properly. Any help is appreciated, and be gentle I am new at this lol. Thank you in advance.
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
struct payroll
{
char name [MAX][21];
char pin [MAX][7];
float hours[MAX];
float hourly_pay[MAX];
float gross_pay[MAX];
float net_pay[MAX];
float overtime_pay[MAX];
float deductions[MAX];
};
typedef struct payroll PAYROLL;
void funcoutput (PAYROLL);
int main( )
{
PAYROLL employee;
int i;
for (i=0;i<=MAX;i++)
{
printf ("Enter the employees last name:\n");
scanf("%s", &employee.name[i]);
printf ("Enter the employees 6 character ID:\n");
scanf("%s", &employee.pin[i]);
printf ("Enter the employees hours for the week:\n");
scanf ("%f", &employee.hours[i]);
printf ("Enter the employees hourly rate of pay: \n");
scanf ("%f", &employee.hourly_pay[i]);
printf ("Enter any employee ovetime hours, hours exceeding 40: \n");
scanf ("%f", &employee.overtime_pay[i]);
employee.overtime_pay[i] = employee.overtime_pay[i] * 1.5;
employee.gross_pay[i] = employee.hours[i] + employee.hourly_pay[i] + employee.overtime_pay[i];
employee.deductions[i] = employee.gross_pay[i] * .25;
employee.net_pay[i] = employee.gross_pay[i] - employee.deductions[i];
}
funcoutput (employee);
return 0;
}
void funcoutput (PAYROLL employee1)
{
int i;
for (i=0;i<MAX;i++)
{
printf("Name:%s ID:%s Hours:%8.2f Hourly rate:$%8.2f Gross pay:$%8.2f Deductions:$%8.2f Net pay:$%8.2f\n",
employee1.name[i],employee1.pin[i],employee1.hours[i],employee1.hourly_pay[i],
employee1.gross_pay[i],employee1.deductions[i],employee1.net_pay[i]);
}
return;
}
MAXappears nowhere in this declaration), then create an array ofMAXlength of those;PAYROLL emp[MAX];In other words, don't use a struct with array members (name and pin not withstanding); use an array of structs. Does that make sense?<=with<.