Question: *This question was answered but the program wont work* In C programming, Using a text editor , create the employee file shown it the following

*This question was answered but the program wont work*

In C programming,

Using a text editor , create the employee file shown it the following Table:

This should be tabbed so that the value line up with the words. Couldnt get the Post a Question box to tab.

Employee No. Department Pay Rate Exempt Hours Worked

0101 41 8.11 Y 49

0722 32 7.22 N 40

1273 23 5.43 Y 39

2584 14 6.74 N 45

Name it weeklyTimesheet.txt.

Write a program to read weeklyTimesheet.txt and create a payroll register file. Name it payroll.txt . The register will contain the following data:

a. Employee Number

b. Department

c. Pay rate

d. Exempt

e. Hours worked

f. Base pay (pay rate * hrs worked (40 hrs or below))

g. Overtime pay (non-exempt employee, calculated at 1.5 pay rate for hrs over 40)

h. Total pay

Present this data in an appropriately formatted table. Send all output to the text file as well as the standard output stream. This prgram should have error checking for opening and closing the file along with seperating the prgram into different functions for readabilty. You are not to use strings in this program as you have not learned how to impliment them properly.

#include #include

//Function that reads and process data void process(FILE *ifp, FILE *ofp) { int empNo, dept, hrsWorked; float payRate; char exempt; float basePay, otPay, totalPay;

//Printing header in output file fprintf(ofp, " %-15s %-10s %-10s %-10s %-10s %-10s %-10s ", "Employee Number", "Department", "Pay rate", "Exempt", "Hours worked", "Base pay", "Overtime pay", "Total pay"); printf(" %-15s %-10s %-10s %-10s %-10s %-10s %-10s ", "Employee Number", "Department", "Pay rate", "Exempt", "Hours worked", "Base pay", "Overtime pay", "Total pay");

//Reading data while(!feof(ifp)) { //Reading a line of data fscanf(ifp, "%d %d %f %c %d", &empNo, &dept, &payRate, &exempt, &hrsWorked);

//Processing pay if(hrsWorked > 40 && exempt == 'N') { basePay = hrsWorked*payRate;

//Overtime otPay = (hrsWorked-40) * 1.5 * payRate;

//Total Pay totalPay = basePay + otPay; } else { basePay = hrsWorked*payRate; totalPay = basePay; }

//Printing a line fprintf(ofp, " %-015d %-10d %-10.2f %-10c %-10d %-10.2f %-10.2f %-10.2f ", empNo, dept, payRate, exempt, hrsWorked, basePay, otPay, totalPay); printf(" %-15d %-10d %-10.2f %-10c %-10d %-10.2f %-10.2f %-10.2f ", empNo, dept, payRate, exempt, hrsWorked, basePay, otPay, totalPay); }

//Closing files fclose(ifp); fclose(ofp); }

//Main function int main() { //File pointer declaration FILE *ifp, *ofp;

//Opening files for processing ifp = fopen("weeklyTimesheet.txt", "r"); ofp = fopen("payroll.txt", "w");

//Checking file status if(ifp == NULL || ofp == NULL) { printf(" Can't open files... "); return -1; }

//Processing files process(ifp, ofp);

printf(" "); return 0; }

The file it creates has nothing in it and it is not reading or writting anything to the payroll file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!