fork download
  1. #include <stdio.h>
  2.  
  3. #define SIZE 2 // Define Number of Employees "SIZE" to be 2
  4.  
  5. struct Employee
  6. {
  7. int id;
  8. int age;
  9. double salary;
  10. }; // Declare Struct Employee
  11.  
  12. /* main program */
  13. int main(void)
  14. {
  15. int i = 0;
  16. double tempsalary = 0.0;
  17.  
  18. int option = 0;
  19. printf("---=== EMPLOYEE DATA ===---\n\n");
  20.  
  21. struct Employee emp[SIZE] = { 0, 0, 0 };
  22.  
  23. do
  24. {
  25. // Print the option list
  26. printf("1. Display Employee Information\n");
  27. printf("2. Add Employee\n");
  28. printf("0. Exit\n\n");
  29. printf("Please select from the above options: ");
  30. scanf("%d", &option); // Capture input to option variabl
  31. printf("\n");
  32.  
  33. switch (option)
  34. {
  35. case 0: // Exit the program
  36.  
  37. printf("Exiting Employee Data Program.\nGood Bye!!!");
  38.  
  39. break;
  40.  
  41. case 1:
  42.  
  43. printf("EMP ID EMP AGE EMP SALARY\n");
  44. printf("====== ======= ==========\n");
  45. for (int i = 0; i < SIZE; i++)
  46. {
  47. printf("%6d%9d%11.2lf", emp[i].id, emp[i].age, emp[i].salary);
  48. printf("\n");
  49. }
  50.  
  51. break;
  52.  
  53. case 2: // Adding Employee
  54.  
  55. if (i > SIZE)
  56. {
  57. printf("ERROR!!! Maximum Number of Employees Reached\n");
  58. }
  59.  
  60. printf("Adding Employee\n");
  61. printf("===============\n");
  62. printf("Enter Employee ID: ");
  63. scanf("%d", &emp[i].id);
  64. printf("Enter Employee Age: ");
  65. scanf("%d", &emp[i].age);
  66. printf("Enter Employee Salary: ");
  67. scanf("%lf", &emp[i].salary);
  68. // printf("%.2lf",emp[i].salary);
  69. printf("\n");
  70.  
  71. i++;
  72.  
  73. break;
  74.  
  75. default:
  76. printf("ERROR: Incorrect Option: Try Again\n\n");
  77. }
  78.  
  79. } while (option != 0);
  80.  
  81. return 0;
  82. }
Success #stdin #stdout 0s 9432KB
stdin
2
1441
26
7989.98
1
0
stdout
---=== EMPLOYEE DATA ===---

1. Display Employee Information
2. Add Employee
0. Exit

Please select from the above options: 
Adding Employee
===============
Enter Employee ID: Enter Employee Age: Enter Employee Salary: 
1. Display Employee Information
2. Add Employee
0. Exit

Please select from the above options: 
EMP ID  EMP AGE EMP SALARY
======  ======= ==========
  1441       26    7989.98
     0        0       0.00
1. Display Employee Information
2. Add Employee
0. Exit

Please select from the above options: 
Exiting Employee Data Program.
Good Bye!!!