Putting the new employee

Assignment Help Business Management
Reference no: EM132143110

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 <stdio.h>

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;

}

Reference no: EM132143110

Questions Cloud

C program with a function named randombetween : Need guidance on coming up with a C program with a function named randomBetween that returns a random floating point number between the two floating point
Concerning the economic order quantity model : Which one of the following statements concerning the economic order quantity (EOQ) model is TRUE?
Describe reinforcement perspective-social learning theory : Describe the reinforcement perspective and social learning theory and how they can be used to motivate employees.
Describe the considerations that you would take into account : Describe the considerations that you would take into account when selecting the menu style for an application and why. Support your response with examples.
Putting the new employee : 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).
Kotler expect the final consumers to pay for this product : What does Kotler expect the final consumers to pay for this product at retail stores?
Create a management plan containing eight to ten stages : You have recently started your own software design company. You discover that your local DMV is looking to build a system that will allow receptionists.
Determine whether this leader acted ethically or unethically : Analyze your leader's (in your particular position) use of power in a particular situation. Determine whether this leader acted ethically or unethically
Patient protection and affordable care act : As a result of the Patient Protection and Affordable Care Act,

Reviews

Write a Review

Business Management Questions & Answers

  How can companies attract highly competent women

Write a 10-page paper concerning whether or not women should be solicited for overseas assignment, how can companies attract highly competent women, and how can they ensure that women will be successful?

  Find the evaluate training programs

What motivation do companies have to evaluate training programs and how would evaluation help the company reach its long term goals?

  Requirements of equal employment opportunity

Prepare a 700- to 1050-word paper in which you discuss the elements of affirmative action as it applies to public sector and private sector employers and how it interacts with Title VII requirements of Equal Employment Opportunity. Your paper must..

  Experiencing cialdini presentation style

In addition to experiencing Cialdini's presentation style from his narration in the Background video, view some of his other videos on YouTube. Find at least one that discusses persuasion. Post the link to the video and share your thoughts.

  Find an actual business in that country

Turn in the letter, and then write a one-paragraph (300+ words) explanation of how you met the needs of the diverse cultural audience in terms of style, tone, level of content, format, and sales tactics.

  Conditions produce downward movement of price

Assume Qs represents the quantity supplied at a given price and Qd represents the quantity demanded at the same given price.Wich of the following market conditions produce a downward movement of the price?

  Types of diversity are present in the workforce

What are the types of diversity are present in the workforce? What are the impacts of globalization, multiculturalism, and a diverse workforce? What is your experience with these? . Also, diversity is sometimes perceived as a negative, a nuisan..

  Difficulties you envision in the project and why

Consider the average output rate out of the FDA review. If there are 200 projects in the pipeline for basic research, how does this project fare? What kind of performance is required to warrant a financial investment?

  Discuss best practices for microsoft windows group policy

Discuss best practices for Microsoft Windows Group Policy using the text Internet and/or your job as reference for full credit?

  Pay a royalty to ?lm studios

Each ?rm must also pay a royalty to ?lm studios,and the per ?lm royalty rate (r) is an increasing function of total industry output (Q):

  From whom would you prefer to get this information

Imagine that you are an employee of a large organization - As a manager of change, how might you use these insights in terms of forming a media communications strategy?

  Analyze the alpaca farmer co-op product disparagement case

Analyze the alpaca farmer co-op’s product disparagement case against Ellen, Persons R Persons and PETA. Comprise defences for all three.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd