Salary Slip Generator Using C Program
Salary Slip Generator Using C Program
/*
expt no: 11
*/
#include <stdio.h>
#include <stdlib.h>
struct detail {
int empid;
char name[20];
char dept[20];
char grade;
char gender;
};
int main()
struct detail s;
FILE *fp;
int i=0;
char val;
if((fp=fopen("empdet.txt","w"))==NULL)
exit(1);
for(i=0;;i++)
printf("empid:\n");
scanf("%d", &s.empid);
printf("name:\n");
scanf("%s", s.name);
printf("department:\n");
scanf("%s", s.dept);
printf("grade:\n");
printf("gender:\n");
fwrite(&s,sizeof(s),1,fp);
fflush(stdin);
printf("press 'y' to continue and 'e' to exit \n");
scanf("%c", &val);
if(val=='y')
continue;
else
break;
fclose(fp);
int id;
scanf("%d",&id);
if((fp=fopen("empdet.txt","r"))==NULL)
while(!feof(fp))
fread(&s,sizeof(s),1,fp);
if(id==s.empid)
printf("empid:%d\ngrade:%c\ngender%c\t\n",s.empid,s.grade,s.gender);
long base1=120000,hra1=36000,da1=39600,ta1=14000;
long base2=90000,hra2=18000,da2=29700,ta2=7500;
long base3=40000,hra3=4000,da3=13200,ta3=5000;
long gross=0,net=0,deduct=0;
if(s.grade=='a'&&s.gender=='m')
gross=base1+hra1+da1+ta1;
deduct=(float)(gross*(0.1))+((base1+da1)*(0.1));
net=gross-deduct;
if(s.grade=='b'&&s.gender=='m')
gross=base2+hra2+da2+ta2;
deduct=(float)(gross*(0.1))+((base1+da1)*(0.1));
net=gross-deduct;
if(s.grade=='c'&&s.gender=='m')
{
gross=base3+hra3+da3+ta3;
deduct=(float)(gross*(0.1))+((base1+da1)*(0.1));
net=gross-deduct;
if(s.grade=='a'&&(s.gender=='f'||s.gender=='x'))
gross=base1+hra1+da1+ta1+2000;
deduct=(float)(gross*(0.1))+((base1+da1)*(0.05));
net=gross-deduct;
if(s.grade=='b'&&(s.gender=='f'||s.gender=='x'))
gross=base2+hra2+da2+ta2+2000;
deduct=(float)(gross*(0.1))+((base1+da1)*(0.05));
net=gross-deduct;
if(s.grade=='c'&&(s.gender=='f'||s.gender=='x'))
gross=base2+hra2+da2+ta2+2000;
deduct=(float)(gross*(0.1))+((base1+da1)*(0.05));
net=gross-deduct;
printf(" your gross salary:%ld\n your deduct %ld your net salary:%ld\n",gross,deduct,net);
}
fclose(fp);
return 0;
Sample input:
empid:
1
name:
venkiboo
department:
cse
grade:
a
gender:
m
press 'y' to continue and 'e' to exit
y
empid:
2
name:
pinky
department:
statistics
grade:
b
gender:
f
press 'y' to continue and 'e' to exit
y
empid:
micky
name:
department:
healthcare
grade:
c
gender:
x
press 'y' to continue and 'e' to exit
e
Sample output:
empid:1
grade: a
gender m
your gross salary: 209600
your deduct 36920
your net salary: 172680