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

  Caselet on michael porter’s value chain management

The assignment in management is a two part assignment dealing 1.Theory of function of management. 2. Operations and Controlling.

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. Due to increase in the preference for light beer drinkers, Chris Prangel wants to introduce light beer version in Mountain Man. An analysis into the la..

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. An analysis into the launch of Mountain Man Light over the present Mountain Man Lager.

  Analysis of the case using the doing ethics technique

Analysis of the case using the Doing Ethics Technique (DET). Analysis of the ethical issue(s) from the perspective of an ICT professional, using the ACS Code of  Conduct and properly relating clauses from the ACS Code of Conduct to the ethical issue.

  Affiliations and partnerships

Affiliations and partnerships are frequently used to reach a larger local audience? Which options stand to avail for the Hotel manager and what problems do these pose.

  Innovation-friendly regulations

What influence (if any) can organizations exercise to encourage ‘innovation-friendly' regulations?

  Effect of regional and corporate cultural issues

Present your findings as a group powerpoint with an audio file. In addition individually write up your own conclusions as to the effects of regional cultural issues on the corporate organisational culture of this multinational company as it conducts ..

  Structure of business plan

This assignment shows a structure of business plan. The task is to write a business plane about a Diet Shop.

  Identify the purposes of different types of organisations

Identify the purposes of different types of organisations.

  Entrepreneur case study for analysis

Entrepreneur Case Study for Analysis. Analyze Robin Wolaner's suitability to be an entrepreneur

  Forecasting and business analysis

This problem requires you to apply your cross-sectional analysis skills to a real cross-sectional data set with the goal of answering a specific research question.

  Educational instructional leadership

Prepare a major handout on the key principles of instructional leadership

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