Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *in_file;//file pointer
FILE *out_file;// file to be saved
char payfile, name[25], greatestNet, leastNet, empnum[5];
float hours, overtime, rate, gross, deduct, net, depart, grossTotal, grossTotal1, netTotal, overTotal, avgGross, salary, stateTax, fedTax, medTax, ssTax;
out_file = fopen ( "C:\\Documents and Settings\\Kevin\\Desktop\\projecttest\\payroll.txt", "w"); //Location of file after it is written
in_file = fopen ( "emps.dat", "r");//file i am opening for program the scan
if( in_file == NULL ) {
printf( "\nThe file cannot be opened.");//Dispayes message if file is not found
printf( "\nPlease check that the file currently exists.");
}
else {
printf( "\nThe output file has been writen.\n"); //Displayes message when program has ran successfully
}
fprintf ( out_file, "Number Name\t\t Rate Hours Salary Department Overtime Gross Deductions Net\n");
while( fscanf( in_file, "%s %s %f %f %f %f", empnum, name, &rate, &hours, &salary, &depart) != EOF ) {
gross = rate*hours;
stateTax = gross*.049;
fedTax = gross*.1115;
medTax = gross*.0145;
ssTax = gross*.0145;
deduct = ssTax+medTax+fedTax+stateTax;
net = gross-deduct;
if (salary >0){
gross = salary;
stateTax = gross*.049;
fedTax = gross*.1115;
medTax = gross*.0145;
ssTax = gross*.0145;
deduct = ssTax+medTax+fedTax+stateTax;
net = gross-deduct;
}
fprintf( out_file, "%-9s %-17s %-9.2f %-9.2f %-9.2f %-13.0f %-10.2f %-11.2f %-10.2f %-9.2f \n", empnum, name, rate, hours, salary, depart, overtime, gross, deduct, net);
}
if (depart=10){
grossTotal = gross+gross+gross+gross+gross;
fprintf ( out_file, "\nTotal Gross For Department 10 = %.2f", grossTotal);
}
fclose (in_file);
fclose (out_file);
system("PAUSE");
return 0;
}