Hmm, there are a couple problems here...
First, your struct itself...
Code:
struct work {
char emp_number[4];
char name[20];
int hours[5];
int rate[4];
};
Let's start with emp_number. Is this supposed to actully be a number? Because if so, then you should be using an int, not an array of char. Having it as a char[4] only makes sense if the employee number can be something like.. 4B3
Why does each employee have 5 different hour values and 4 different rate values?
Unless you have some special reason for using arrays, change hours to an int, rate to an int, and emp_number to an int. (If you do this, then you'll have to change how you input the emp_number to use scanf("%d", list[i].emp_number);)
Your assignment states that you need to use an input function, and output function. Your logic seems to all be there, you just need to change it into a function. Basically, your function will look something like this...
Code:
void getInput (void)
{
for(i=0;i<10;i++){
printf("Enter employee number: ");
scanf("%s", list[i].emp_number);
printf("Enter name: ");
scanf("%s", list[i].name);
printf("Enter hours worked: ");
scanf("%d", list[i].hours);
printf("Enter hourly rate: ");
scanf("%d", list[i].rate);
}
return;
}
No magic there, just copy n' pasting (see how I suggest changing emp_number to a number above).
Really, this assignment looks like the kinda thing you can compartmentalize entirely into functions. Here's what my main would look like...
Code:
int main ()
{
// get 10 employee records from screen.
getInput();
// display gross pay calculated from hours worked and pay rate
displayPayHoursRate();
// Displays totals for hours worked and gross pay; and
// averages for hours worked, pay rate, and gross pay
displayTotalsAverage();
// Sorts the records in ascending employee name order
sortAscendingName();
// redisplaying the employee info proves you sorted it.
displayPayHoursRate();
// exit program
return 0;
}
All the work for this program should be hidden in those functions.