# Structures and Pointers

#### PROGRAM 14: SALARY SLIP USING STRUCTURE AND POINTERS

/*
Generate Pay Slip Using Structures and Pointer
*/

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

void generatePaySlip(struct employee);

struct employee{
int empId;
char name[32];
int basic,HRA;
int insurance,pf;
float gross,net;
};

void main(){
int i,num,flag,empId;
char ch;
struct employee *ptr;
clrscr();
printf("Enter the Number of Employees....");
scanf("%d",&num);
ptr=(struct employee*)malloc(sizeof(struct employee)* num);
printf("\nEnter details for each employee...");
for(i=0;i<num;i++){
printf("\nEnter Employee ID:");
scanf("%d",&(ptr+i)->empId);
printf("\nEnter Employee Name:");
scanf("%s",&(ptr+i)->name);
printf("\nEnter Basic Salary and HRA:");
scanf("%d%d",&(ptr+i)->basic,&(ptr+i)->HRA);
printf("\nEnter PF and Insurance Value:");
scanf("%d%d",&(ptr+i)->pf,&(ptr+i)->insurance);
}

for(i=0;i<num;i++){
(ptr+i)->gross=(ptr+i)->basic+((ptr+i)->HRA*(ptr+i)->basic)/100;
(ptr+i)->net=(ptr+i)->gross-((ptr+i)->pf+(ptr+i)->insurance);
}

while(1){
printf("\nEnter Employee ID to generate Pay Slip...");
scanf("%d",&empId);
flag=0;
for(i=0;i<num;i++){
if(empId==(ptr+i)->empId){
generatePaySlip(ptr[i]);
flag=1;
}
}
if(!flag){
printf("\nNo Recored Found!!!");
}
printf("\nContinue Search. ..?(Y|n)");
ch=getche();
if(ch=='Y'||ch=='y'){
continue;
}
else{
break;
}
}
}

void generatePaySlip(struct employee e){
clrscr();
printf("\n********************************************");
printf("\n* SALARY SLIP *");
printf("\n********************************************");
printf("\n* Employee ID :%d ",e.empId);
printf("\n* Employee Name :%s ",e.name);
printf("\n* Basic Salary :%d ",e.basic);
printf("\n* House Rent Allowance :%d ",e.HRA);
printf("\n* Gross Salary :%.2f ",e.gross);
printf("\n*------------------------------------------*");
printf("\n* DEDUCTIONS *");
printf("\n*------------------------------------------*");
printf("\n* Provident Fund :%d ",e.pf);
printf("\n* Insurance :%d ",e.insurance);
printf("\n*------------------------------------------*");
printf("\n* Net Salary :%.2f ",e.net);
printf("\n********************************************");
}