Ask Business Management Expert

My program needs to create 4 employees (ID 222,333,444,555) and then delete one (ID 333) and add a new employee (ID 666). This all works fine, my issue is that once I display the array instead of putting the new employee (666) in place of the deleted employee (333), it just overwrites the last employee in the array (555) and I can't understand why. I also need to do this without reordering the items in the array, which is also causing an issue. I understand that writing employee[totalEmps].ID = 0; doesn't "delete" that employee and just hides it, but I am unsure of a better way. Output showing my issue is below as well as my code. Code in question is bolded.

1. Display Employee Information

2. Add Employee

3. Update Employee Salary

4. Remove Employee

0. Exit

Please select from the above options: 1

EMP ID EMP AGE EMP SALARY

====== ======= ==========

  222      22  22222.22

  333      33  33333.33

  444      44  44444.44

  555      55  55555.55

1. Display Employee Information

2. Add Employee

3. Update Employee Salary

4. Remove Employee

0. Exit

Please select from the above options: 4

Remove Employee

===============

Enter Employee ID: 333

Employee 333 will be removed

1. Display Employee Information

2. Add Employee

3. Update Employee Salary

4. Remove Employee

0. Exit

Please select from the above options: 2

 

Adding Employee

===============

Enter Employee ID: 666

Enter Employee Age: 66

Enter Employee Salary: 66666.66

1. Display Employee Information

2. Add Employee

3. Update Employee Salary

4. Remove Employee

0. Exit

Please select from the above options: 1

EMP ID EMP AGE EMP SALARY

====== ======= ==========

  222      22  22222.22

  444      44  44444.44

  666      66  66666.66

1. Display Employee Information

2. Add Employee

3. Update Employee Salary

4. Remove Employee

0. Exit

Please select from the above options:

#define _CRT_SECURE_NO_WARNINGS

#define SIZE 4

#include

struct Employee

{

   int ID; // Employee Identification.

   int age; // Employee Age.

   double salary; // Employee Salary.

};

int main(void) {

   int option = 0; // Variable for which option user picks in option list.

   int totalEmps = 0; // Variable for adding employees and displaying information.

   int Num = 0; // Variable for storing number of employees.

   int UserID = 0;

   int i = 0;

   struct Employee employee [SIZE] = { {0} }; // Declare a struct employee array "employee" with SIZE elements and initialize all elements to zero.

   printf("---=== EMPLOYEE DATA ===---nn");

   do { // Do while loop to continue printing out option list while user hasn't pressed 0 to exit.

      printf("1. Display Employee Informationn");

      printf("2. Add Employeen");

      printf("3. Update Employee Salaryn");

      printf("4. Remove Employeen");

      printf("0. Exitnn");

      printf("Please select from the above options: ");

      scanf("%d",&option);

      printf("n");

      switch (option) {

      case 0:   // Exit the program

         printf("Exiting Employee Data Program. Good Bye!!!n");

         break;

      case 1: // Display Employee Data

         printf("EMP ID EMP AGE EMP SALARYn");

         printf("====== ======= ==========n");

         for (Num = 0; Num <= SIZE; Num++) // For loop to continue printing out array if number of employees are less than SIZE.

         {

            if (employee[Num].ID > 0) // If statement to print array if employee ID is greater than 0.

               printf("%6d%9d%11.2lfn", employee[Num].ID, employee[Num].age, employee[Num].salary);

         }

         printf("n");

         break;

      case 2:   // Adding Employee

         printf("Adding Employeen");

         printf("===============n");

         if (totalEmps < SIZE) // If number of employees are less than SIZE, print out info for user to input and add 1 to variable "employee".

         {

            printf("Enter Employee ID: ");

            scanf("%d", &employee[totalEmps].ID);

            printf("Enter Employee Age: ");

            scanf("%d", &employee[totalEmps].age);

            printf("Enter Employee Salary: ");

            scanf("%lf", &employee[totalEmps].salary);

            printf("n");

            totalEmps++;         

         }

         else // Else print out error message.

         {

            printf("ERROR!!! Maximum Number of Employees Reachednn");

         }      

         break;

      case 3: // Updates Employee Salary.

         printf("Update Employee Salaryn");

         printf("======================n");

         do

         {

            i = 0;

            printf("Enter Employee ID: ");

            scanf("%d", &UserID);

            for (totalEmps = 0; totalEmps < SIZE; totalEmps++) {

               if (UserID == employee[totalEmps].ID) {

                  printf("The current salary is %.2lfn", employee[totalEmps].salary);

                  printf("Enter Employee New Salary: ");

                  scanf("%lf", &employee[totalEmps].salary);

                  printf("n");

                  i = 1;

               }

            }

            if (i != 1) {

               printf("*** ERROR: Employee ID not found! ***n");

            }

         } while (i < 1);

         break;

      case 4: // Removes Employees.

         printf("Remove Employeen");

         printf("===============n");

         do

         {

            i = 0;

            printf("Enter Employee ID: ");

            scanf("%d", &UserID);

            for (totalEmps = 0; totalEmps < SIZE; totalEmps++) {

               if (UserID == employee[totalEmps].ID) {

                  printf("Employee %d will be removedn", employee[totalEmps].ID);

                  printf("n");

                  employee[totalEmps].ID = 0;

                  i = 1;

               }

            }

            totalEmps = totalEmps - 1;

            if (i != 1) {

               printf("*** ERROR: Employee ID not found! ***n");

            }

         } while (i == 0);

         break;

      default: // Print error message if user inputs anything thats not on option list.

         printf("ERROR: Incorrect Option: Try Againnn");

      }

   } while (option != 0);

   return 0;

}

Business Management, Management Studies

  • Category:- Business Management
  • Reference No.:- M93130575
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Business Management

Name a company that addressed a recent ethical problem in a

Name a company that addressed a recent ethical problem in a positive way. Also, explain how or if this positively affects us as a community?

When it is appropriate to use the trade-off process what

When it is appropriate to use the trade-off process. What conditions apply, and the technical evaluation criteria that might be used?

Need help with a essay with the following phrase for

Need help with a essay with the following phrase for analyzing : " Capitalism is at the heart of how people and organisations are managed in contemporary society" May i ask for a better explanation of the question? Also ...

How could these three tenets of the auburn creed be used to

How could these three tenets of the Auburn Creed be used to motivate others: "I believe that this is a practical word and that I can count only on what I earn. Therefore, I believe in work, hard work." "I believe in educ ...

How can these two tenets of the auburn creed by used in

How can these two tenets of the Auburn Creed by used in addressing teamwork issues: "I believe in honesty and truthfulness, without which I cannot win the respect and confidence of my fellow men." "I believe in the human ...

Discuss the advantages of having and interacting in a

Discuss the advantages of having and interacting in a diverse workplace. Consider the wide range of ideas and perspectives that a range of team members bring to a team, that are of differing ages, ethnic backgrounds and ...

Parmigiano-reggiano global recognition of geographical

Parmigiano-Reggiano: Global Recognition of Geographical Indications What historical factors have helped support the consortium's claims for the geographic specificity of Parmigiano-Reggiano and Parmesan? What are the eco ...

Communication planthis communication plan will be a roadmap

Communication Plan This communication plan will be a roadmap on how the new division will best be able to communicate with Biotech's corporate headquarters, suppliers, other divisions, and internally. This should lay out ...

Discuss strategies to obtain feedback from a customer and

Discuss strategies to obtain feedback from a customer and clients when working in sales.

Describe different networking methods and the advantages

Describe different networking methods and the advantages and disadvantages of them?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As