In: Computer Science
Write a program to process weekly employee time cards for all employees of an organization. Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week. Each employee is to be paid time and a half for all hours worked over 40. A tax amount of 3.625% of gross salary will be deducted. The program output should show the employee’s number and net pay. Display the total payroll and the average amount paid at the end of the run.
Please do this code in the language C
/* program to process weekly employee time cards for all
employees of an organization*/
#include <stdio.h>
//structure is used to manage 3 dataparts of all employees in
organization
struct emp {
char empid[50];
int wagerate;
int workhours;
} empdata[100];
int main()
{
int num,i,payment,overtime,sum=0;
//varible
declarations
float avg;
struct emp empdata[100];
printf("Enter Number of Employees in Organization\n");
//prompt for asking number of
employees
scanf("%d",&num);
//read
number of employees
for(i=1;i<=num;i++)
//using loop take data of all employees
{
printf("Enter ID\n");
scanf("%s",empdata[i].empid);
//read
employee id
printf("Enter Hourly wage Rate for %s
\n",empdata[i].empid);
scanf("%d",&empdata[i].wagerate);
//read
employee wagerate
printf("Enter Number Hours worked per week by %s
\n",empdata[i].empid);
scanf("%d",&empdata[i].workhours);
//read
employee work hours
//printf("\n%d\t%d\t",empdata[i].wagerate,empdata[i].workhours);
}
for(i=1;i<=num;i++)
//loop to generate outputs
for all employees
{
printf("\nProcessing Payrolls .....\n");
if (empdata[i].workhours>40)
//check
employee done overtime then calculate payment
{
overtime=empdata[i].workhours-40;
payment=(overtime)*((empdata[i].wagerate)/2)+(empdata[i].workhours)*(empdata[i].wagerate);
//calculate payment for employee id if workhours >40
sum=sum+payment;
}
else
{
payment=(empdata[i].workhours)*(empdata[i].wagerate); //calculate
payment for employee id if workhours <40
sum=sum+payment;
}
printf("ID %s\t - \t Payment is \t%d\n
",empdata[i].empid,payment); //display employee id and net
payement
}
printf("Total payroll %d \n ",sum);
//display final pay raoll amount
avg=sum/num;
printf("Average amount paid per employee %f \n ",avg);
//display average payment per
employee
return 0;
}
Note : enter less number of employess to enter less input .
Output :
1111
Enter Hourly wage Rate for 1111
100
Enter Number Hours worked per week by 1111
10
Enter ID
2222
Enter Hourly wage Rate for 2222
200
Enter Number Hours worked per week by 2222
10
Processing Payrolls .....
ID 1111 - Payment is 1000
Processing Payrolls .....
ID 2222 - Payment is 2000
Total payroll 3000
Average amount paid per employee 1500.000000