Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.81 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4.  
  5. #define  SIZE 4
  6.  
  7. // Declare Struct Employee
  8. struct employee {
  9.     int id;
  10.     int age;
  11.     double salary;
  12. };
  13.  
  14. /* main program */
  15. int main(void) {
  16.     int l = 0, i = 0, k = 0, j = 0;
  17.     int option = 0;
  18.     int empId;
  19.     double empSalary;
  20.     int empFound = 0;
  21.     printf("---=== EMPLOYEE DATA ===---\n\n");
  22.  
  23.  
  24.     struct employee emp[SIZE] = { {0} };
  25.     do {
  26.         printf("1. Display Employee Information\n");
  27.         printf("2. Add Employee\n");
  28.         printf("3. Update Employee Salary\n");
  29.         printf("4. Remove Employee\n");
  30.         printf("0. Exit\n\n");
  31.         printf("Please select from the above options: ");
  32.  
  33.         scanf("%d", &option);
  34.         printf("\n");
  35.  
  36.         switch (option) {
  37.         case 0:
  38.             break;
  39.         case 1:
  40.             printf("EMP ID  EMP AGE EMP SALARY\n");
  41.             printf("======  ======= ==========\n");
  42.             for (j = 0; j < i; j++) {
  43.                 printf("%6d%9d%11.2lf\n", emp[j].id, emp[j].age, emp[j].salary);
  44.             }
  45.             printf("\n");
  46.             break;
  47.         case 2:
  48.             printf("Adding Employee\n");
  49.             printf("===============\n");
  50.             if (i >= SIZE) {
  51.                 printf("ERROR!!! Maximum Number of Employees Reached\n\n");
  52.             }
  53.             else {
  54.                 printf("Enter Employee ID: ");
  55.                 scanf("%d", &emp[i].id);
  56.                 while (emp[i].id < 0) {
  57.                     printf("\nPlease input a value higher than 0: ");
  58.                     scanf("%d", &emp[i].id);
  59.                 }
  60.                 printf("Enter Employee Age: ");
  61.                 scanf("%d", &emp[i].age);
  62.                 printf("Enter Employee Salary: ");
  63.                 scanf("%lf", &emp[i].salary);
  64.                 printf("\n");
  65.                 i++;
  66.             }
  67.             break;
  68.         case 3:
  69.             printf("Update Employee Salary\n");
  70.             printf("======================\n");
  71.             do {
  72.                 printf("Enter Employee ID: ");
  73.                 scanf("%d", &empId);
  74.                 for (k = 0; k < SIZE; k++) {
  75.                 if (emp[k].id == empId) {
  76.                     printf("The current salary is %0.2lf\n", emp[k].salary);
  77.                     printf("Enter Employee New Salary: ");
  78.                     scanf("%lf", &empSalary);
  79.                     emp[k].salary = empSalary;
  80.                     empFound = 1;
  81.                     printf("\n");
  82.  
  83.                 }
  84.             }
  85.                 if (empFound == 0) {
  86.                 printf("*** ERROR: Employee ID not found! ***\n");
  87.             }
  88.             } while (empFound != 1);
  89.             break;
  90.         case 4:
  91.             printf("Remove Employee\n");
  92.             printf("===============\n");
  93.                 printf("Enter Employee ID: ");
  94.                 scanf("%d", &empId);
  95.                 l = 0;
  96.                 empFound = 0;
  97.                 while (empFound == 0) {
  98.                     l++;
  99.                     if (empId == emp[l].id) {
  100.                         printf("Employee %d will be removed\n\n", empId);
  101.                         empFound = 1;
  102.                     }
  103.                     if (empFound == 0) {
  104.                         printf("*** ERROR: Employee ID not found! ***\n");
  105.                     }
  106.                 }
  107.                 for (l = l; l < 4; l++) {
  108.                     emp[l].id = emp[l + 1].id;
  109.                     emp[l].age = emp[l + 1].age;
  110.                     emp[l].salary = emp[l + 1].salary;
  111.                 }
  112.                 i--;
  113.                 break;
  114.         default:
  115.             printf("ERROR: Incorrect Option: Try Again\n\n");
  116.         }
  117.     } while (option != 0);
  118.  
  119.     printf("Exiting Employee Data Program. Good Bye!!!\n");
  120.  
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement