Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Describe how the study of leadership theory ethics and

Describe how the study of leadership theory, ethics and social responsibility has and will continue to help an individual in college become a more effective manager.

Write template function called sumsmall that takes an array

Write template function called sumSmall that takes an array of type T* and length as parameters. What type should it return?In the function, sum all values THAT ARE LESS THAN 10. In other words, if the value is 10 or gre ...

Identify some managerial jobs that are highly affected by

Identify some managerial jobs that are highly affected by human behavior and others that are less so. Which would you prefer? Why?

Consider the ip rights to the information in the design

Consider the I.P. rights to the information in the design, manufacturing and advertising of a wireless computer modem. For those of you who are not sure what that is, if you have a WiFi network set up at home or in your ...

Scenario you have been asked to develop a company policy on

Scenario: You have been asked to develop a company policy on what should be done in the event of a data breach, such as unauthorized access to your company's customer database. What sort of process would you use to devel ...

What kind of questions can you ask when choosing a location

What kind of questions can you ask when choosing a location for a restaurant?

Daniel goleman talks about multiple strengths associated

Daniel Goleman talks about multiple strengths associated with the establishment of sound group structure within an organization what is this and why is it important.

Consider yourself the senior manager of the irs tax exempt

Consider yourself the senior manager of the IRS Tax Exempt Organization when the situation described above occurred. Describe in detail how you would apply the Four Steps of Feedback Control to monitor and regulate the o ...

Describe the difference between financial accounting and

Describe the difference between financial accounting and managerial accounting. Give examples of the uses of each one.

Please respondwhat are some other ways to troubleshoot

PLEASE RESPOND What are some other ways to troubleshoot reduced speed or latency? Or to find out what is using all the bandwidth? Perhaps might incorporate parts of this into own three issues.

  • 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