-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment4.c
73 lines (65 loc) · 1.66 KB
/
Assignment4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
struct Employee{
char name[100];
int age;
float basic_salary;
float total_salary;
float bonus;
};
void emp_bonus(struct Employee E[])
{
for(int i=0;i<50;i++){
if(E[i].age>50){
E[i].bonus = (E[i].basic_salary*0.4);
E[i].total_salary = E[i].basic_salary+E[i].bonus;
}
else{
E[i].bonus = (E[i].basic_salary*0.25);
E[i].total_salary = E[i].basic_salary+E[i].bonus;
}
}
printf("\n\n----- Information Dashboard -----\n\n");
for(int i=0;i<50;i++){
printf("\tEmployee %d.\n",i+1);
printf("\tName: ");
puts(E[i].name);
printf("\tTotal Salary: %f",E[i].total_salary);
printf("\n\n");
}
}
int main()
{
struct Employee E[50];
printf("----- Enter Employee Information -----\n\n");
for(int i=0;i<50;i++){
printf("\tEmployee %d.\n",i+1);
printf("\tName: ");
fflush(stdin);
gets(E[i].name);
printf("\tAge: ");
fflush(stdin);
scanf("%d",&E[i].age);
printf("\tBasic Salary: ");
fflush(stdin);
scanf("%f",&E[i].basic_salary);
fflush(stdin);
printf("\n");
}
emp_bonus(E);
//FILE
FILE *fptr;
fptr = fopen("Employee_Data.txt","w");
if(fptr == NULL){
printf("FILE opening unsuccessful!");
exit(0);
}
fprintf(fptr,"\t----- Employee Data -----\n\n");
for(int i=0;i<50;i++){
fprintf(fptr,"\tEmployee %d.\n",i+1);
fprintf(fptr,"\tName: %s\n",E[i].name);
fprintf(fptr,"\tAge : %d\n",E[i].age);
fprintf(fptr,"\n");
}
fclose(fptr);
return 0;
}