#include<stdio.h>
#include<conio.h>
#include<string.h>


FILE *fp1, *fp2;
int count;
struct record
{
char name[20];
int empnum;
char depart[20];
float hours;
float rate;
};

void main()
{

struct record h;
int acount=0,adcount=0,scount=0;
float grosspay,totalg=0;
float tax,totalt=0;
float health,totalh=0;
float pension,totalp=0;
float netpay,totaln=0;
float deductions;

clrscr();

fp1=fopen("employ.dat","r");
fp2=fopen("payrol.dat","w");
count = 0;
printf(" ""Page1\n");
printf(" ""ABC COMPANY EMPLOYEE REPORT""\n");
printf("------------------------------------------\n");
printf("%5s %20s %10s %12s %5s %10s %9s %7s\n","Name","Empnumber","Depart","Tax","Health","Pension","Netpay");
printf("___________________________________________________________________________________\n");

while(fread(&h,sizeof(struct record),1,fp1)==1)
{
grosspay=h.hours*h.rate;
tax = 0.155 * grosspay;
pension=0.03*grosspay;
deductions=(tax+health+pension);
netpay=grosspay-deductions;
totalg=totalg+grosspay;
totalt=totalt+tax;
totalh=totalp+pension;
totaln=totaln+netpay;

printf("%2s\t %5d\t %10s\t %4.2f\t %4.2f\t %4.2f\t %4.2f\t %4.2f\n",h.name,h.empnum,h.depart,grosspay,tax,health,pension,netpay);
if(strcmp(h.depart,"Sales")==0
scount=scount+1;
else if(strcmp(h.depart,"Admin")==0)
adcount=adcount+1;
else
acount=acount+1;
count++;
}
printf("__________________________________________\n");
printf("TOTALS %4.2f\t %4.2\t %4.2f\t %4.2f\t %4.2f\n",totalg,totalt,totalh,totalp,totaln);

printf("Total Number From Sales Department:%d\n",scount);
printf("Total Number From Sales Department:%d\n",scount);
printf("Total Number From Admin Department:%d\n",adcount);
printf("Total Number From Accounts Department:%d\n",&acount);
printf("Total Number Of Employees:%d\n",count);
fwrite(&h,sizeof(h),1,fp2);

fclose(fp1);
fclose(fp2);
}

this sholud be in c code

This does look like C code. It looks to me like you are just reading one element of your data file. I would read this into an array and go from there.

What does your data file look like?

Are you simply writing the same file back out?

This code needs to be corrected:

if(strcmp(h.depart,"Sales")==0

to:

if(strcmp(h.depart,"Sales")==0)

Good luck ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.