![]() |
| | #1 |
| Registered User Join Date: Jan 2002
Posts: 2
| Accepts ten employee records (structures) from the screen employee number employee name hours worked pay rate Displays the records to the screen with a gross pay calculated from hours worked and pay rate Displays totals for hours worked and gross pay; and averages for hours worked, pay rate, and gross pay Sort the records in ascending employee name order. More than one function must be used (main, input, output) or (main, input, output, sort). but theres no example of this anywhere on the internet or in the C book , trust me i've looked. heres what i have so far but theres complier erros. i'm so stuck please help. #include<stdio.h> struct work { char emp_number[4]; char name[20]; int hours[5]; int rate[4]; }; struct work list[10]; void main(){ /************ LOOP TO INPUT THE DATA FOR 10 PEOPLE ************/ { int i, emp_hours, emp_rate; 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); } printf("\n"); printf("EMP# Name Hours Rate\n"); printf("=== ==== ======= ======\n"); { /*Calculate Gross Pay */ hours(sum= sum + individual; #include<stdio.h> } } whats wrong why wont it let me add the elements of the structure please help |
| Crocksmyworld is offline | |
| | #2 |
| Registered User Join Date: Jan 2002
Posts: 1
| sorry dude i've been programming for years and this is over my head. it would take a true genius to figure this out!!! |
| hackerr425 is offline | |
| | #3 |
| Hamster without a wheel Join Date: Aug 2001
Posts: 1,385
| hackerr425 - what is the point of posting a reply to say you dont know the answer??? corcksmyworld - post the error messages thrown up by the compiler and which compiler you are using.
__________________ Monday - what a way to spend a seventh of your life |
| iain is offline | |
| | #4 |
| Registered User Join Date: Jan 2002
Posts: 9
| iain may be able to help you faster than I can, but as for this part of your program I have made a few small changes and it compiles. You still need to work out the sort, and print routines. #include<stdio.h> struct work { char emp_number[4]; char name[20]; int hours[5]; int rate[4]; }; struct work list[10]; int main(){ /************ LOOP TO INPUT THE DATA FOR 10 PEOPLE ************/ //{ one too many curly brackets int i, emp_hours, emp_rate; 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); } printf("\n"); printf("EMP# Name Hours Rate\n"); printf("=== ==== ======= ======\n"); { /*Calculate Gross Pay */ //hours(sum= sum + individual); //#include<stdio.h> I dont know why this is here } } |
| mervin is offline | |
| | #5 |
| Registered User Join Date: Jan 2002
Posts: 2
| Thanks for taking the time out to help Melvin it means a lot to me. How would you go about totaling the elements of the structure for example totaling list[i].hours since hours is what needs to be totaled and it is a member of the structure?? |
| Crocksmyworld is offline | |
| | #6 |
| Registered User Join Date: Sep 2001
Posts: 752
| 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];
};
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;
}
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;
}
__________________ Callou collei we'll code the way Of prime numbers and pings! Last edited by QuestionC; 01-20-2002 at 12:00 AM. |
| QuestionC is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| returning char arrays!!!! | bobthebullet990 | C Programming | 2 | 03-30-2006 07:05 AM |
| code condensing | bcianfrocca | C++ Programming | 4 | 09-07-2005 09:22 AM |
| Storing strings in 2d char arrays problem | rainmanddw | C++ Programming | 5 | 10-22-2003 05:41 PM |
| malloc with arrays of strings | Lib | C Programming | 2 | 08-03-2003 10:46 PM |
| arrays of char strings | Unregistered | C Programming | 2 | 10-24-2001 04:46 PM |