Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* structure to store employee salary details */
- struct employee {
- int empId;
- char name[32];
- int basic, bonus;
- int absent, salaryDeduc;
- float gross, net;
- };
- /* prints payslip for the requested employee */
- void printSalary(struct employee e1) {
- printf("Salary Slip of %s:\n", e1.name);
- printf("Employee ID: %d\n", e1.empId);
- printf("Basic Salary: %d\n", e1.basic);
- printf("Bonus: %d\n", e1.bonus);
- printf("Gross Salary: %.2f PHP\n", e1.gross);
- printf("\nDeductions: \n");
- printf("Absent: %d\n", e1.absent);
- printf("Salary Deduction: %d\n", e1.salaryDeduc);
- printf("\nNet Salary: %.2f PHP\n\n", e1.net);
- return;
- }
- /* display all the employee records entered */
- void display(struct employee e1) {
- printf("%d \t %s \t %d \t %d \t %d \n", e1.empId, e1.name, e1.basic, e1.bonus, e1.absent);
- return;
- }
- int main() {
- int i, ch, num, flag, empID;
- int choice;
- struct employee *e1;
- /* get the number of employees from the user */
- printf("Enter the number of employees:");
- scanf("%d", &num);
- /* dynamically allocate memory to store employee salary details */
- e1 = (struct employee *)malloc(sizeof(struct employee) * num);
- /* get the employee salary details from the customer */
- printf("Enter your input for every employee:\n");
- for (i = 0; i < num; i++) {
- printf("Employee ID:");
- scanf("%d", &(e1[i].empId));
- getchar();
- printf("Employee Name:");
- fgets(e1[i].name, 32, stdin);
- e1[i].name[strlen(e1[i].name) - 1] = '\0';
- printf("Basic Salary:");
- scanf("%d", &(e1[i].basic));
- printf("Bonus:");
- scanf("%d", &(e1[i].bonus));
- printf("Enter the deductions: \n");
- printf("Absent:");
- scanf("%d", &(e1[i].absent));
- printf("\n");
- }
- /* printing payslip for the given employee ID */
- while (1) {
- printf("\n EMPLOYEE PAYROLL SYSTEM \n");
- printf("\n\n*****CHOOSE YOUR OPTION*****\n");
- printf("1) SHOW ALL RECORDS\n");
- printf("2) ADD NEW EMPLOYEE RECORD\n");
- printf("3) PRINT THE SALARY SLIP\n");
- printf("4) EXIT\n");
- printf("Enter your choice : ");
- scanf("%d", &choice);
- if (choice != 5) {
- switch(choice){
- case 1 : /*printing all the records entered before printing the slip */
- printf("\nEmp. ID. Emp.Name \t Basic \t Bonus \t Absent \n") ;
- for (i = 0; i < num; i++) {
- display(e1[i]);
- }
- break;
- case 2 : /*adding a new member in the employee list created */
- num++;
- i = num-1;
- printf("Employee ID:");
- scanf("%d", &(e1[i].empId));
- getchar();
- printf("Employee Name:");
- fgets(e1[i].name, 32, stdin);
- e1[i].name[strlen(e1[i].name) - 1] = '\0';
- printf("Basic Salary:");
- scanf("%d", &(e1[i].basic));
- printf("Bonus:");
- scanf("%d", &(e1[i].bonus));
- printf("Enter the deductions:\n");
- printf("Absent:");
- scanf("%d", &(e1[i].absent));
- printf("\n");
- break;
- case 3 : /* gross and net salary calculation */
- for (i = 0; i < num; i++) {
- e1[i].gross = e1[i].basic + e1[i].bonus;
- e1[i].salaryDeduc = (0.04 * e1[i].absent) * e1[i].basic;
- e1[i].net = e1[i].gross - e1[i].salaryDeduc;
- }
- printf("Enter employee ID to get payslip:");
- scanf("%d", &empID);
- flag = 0;
- for (i = 0; i < num; i++) {
- if (empID == e1[i].empId) {
- printSalary(e1[i]);
- flag = 1;
- }
- }
- if (!flag) {
- printf("No Record Found!!\n");
- }
- break;
- case 4 : //printf("5");
- break;
- default: printf("error");
- }
- printf("\n Do You Want To Continue(1/0):");
- scanf("%d", &ch);
- } else {
- ch = 0;
- }
- if (!ch) {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement