Sample employee payslip program

#include
struct emp
{
double bp,hra,da,cca,ded,gp,np;
char empname[20];
};
struct emp e[50];
int i=0;
main()
{
int ch;
// struct emp e;
int addemp();
void display();
int delemp();
do
{
printf("\n1.Add 2.Delete 3.Display 4.Exit \nEnter the choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: i=addemp(); break;
case 2: i=delemp(); break;
case 3: display(); break;
}
}while(ch!=4);
}
int addemp()
{
i=i+1;
e[i].ded=1000.00;
printf("\nEnter the Employee Name : ");
scanf("%s",e[i].empname);
printf("\nEnter the Basic Pay : ");
scanf("%lf",&e[i].bp);
e[i].da=0.9*e[i].bp;
e[i].hra=0.2*e[i].bp;
e[i].cca=0.1*e[i].bp;
e[i].gp=e[i].bp+e[i].da+e[i].hra+e[i].cca;
e[i].np=e[i].gp-e[i].ded;
return i;
}
int delemp()
{
printf("The deleted employee name is %s",e[i].empname);
i=i-1;
return i;
}
void display()
{
int j,k=0;
printf("\t\t\t\tEMPLOYEE PAYSLIP\n\n");
printf("\nSNO EMPLOYEE NAME BASIC DA HRA CCA GP DED NP\n");
printf("--------------------------------------------------------------------------\n");
for(j=1;j<=i;j++)
{
k=k+1;
printf("%3d %13s %7.2f %7.2f %7.2f %7.2f %8.2f %7.2f %8.2f",k,e[j].empname,e[j].bp,e[j].da,e[j].hra,e[j].cca,e[j].gp,e[j].ded,e[j].np);
printf("\n");
}

}

No comments: