0% found this document useful (0 votes)
29 views

Salary Slip Generator Using C Program

The document contains C code to define a structure with employee details, write those details to a file, read an employee ID from input and output the corresponding employee's salary details including gross, deductions, and net salary. It takes employee ID, name, department, grade, and gender as input, calculates salaries based on those fields, and writes the output to the console.

Uploaded by

Venki Boo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Salary Slip Generator Using C Program

The document contains C code to define a structure with employee details, write those details to a file, read an employee ID from input and output the corresponding employee's salary details including gross, deductions, and net salary. It takes employee ID, name, department, grade, and gender as input, calculates salaries based on those fields, and writes the output to the console.

Uploaded by

Venki Boo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Source code:

/*

author: vengadesa boopathi;

dept: cse 1-1st year

expt no: 11

date :30 :09:2022

*/

#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)

printf("error:cannot open file");

exit(1);

printf("enter the details \n");

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");

scanf(" %c", &s.grade);

printf("gender:\n");

scanf(" %c", &s.gender);

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;

printf("enter the employees id whose salary slip you need:\n");

scanf("%d",&id);

if((fp=fopen("empdet.txt","r"))==NULL)

printf("error file cannot be opened");

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:

enter the details

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

enter the employees id whose salary slip you need:


1

Sample output:
empid:1
grade: a
gender m
your gross salary: 209600
your deduct 36920
your net salary: 172680

You might also like