Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Business Management Expert

This is some code I have been working on. It is a menu with an option to input employee information and a table to view it in. The code works for the most part - except after you have filled the maximum number of employees and attempt to insert another one and the correct error message appears. Then, when the option is selected to display the employee's information, it will only correctly show the last employee entered and the rest will all be 0s. I haven't the foggiest where the issue is. Any hint would be appreciated. I am not asking for the answer I'm asking to be pointed to the section of the code that is causing this extremely specific issue. To narrow it down.

#define _CRT_SECURE_NO_WARNINGS

#define SIZE 2

#include 

// Define Number of Employees "SIZE" to be 2

// Declare Struct Employee

struct Employee {

int id, age;

double salary;

};

/* main program */

int main(void) {

int option = 0;

// Declare a struct Employee array "emp" with SIZE elements

// and initialize all elements to zero

struct Employee emp[SIZE] = { { 0 } };

int counter = 0;

int employeesNumber = 0;

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

do {

// Print the option list

printf("1. Display Employee Informationn");

printf("2. Add Employeen");

printf("0. Exitnn");

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

// Capture input to option variable

scanf("%d", &option);

printf("n");

switch (option) {

case 0: // Exit the program

break;

case 1: // Display Employee Data

// @IN-LAB

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

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

// Use "%6d%9d%11.2lf" formatting in a

// printf statement to display

// employee id, age and salary of

// all employees using a loop construct

if (emp[0].id > 0) {

for (counter = 0; counter < SIZE; counter++)

printf("%6d%9d%11.2lfn", emp[counter].id, emp[counter].age, emp[counter].salary);

printf("n");

}

// The loop construct will be run for SIZE times

// and will only display Employee data

// where the EmployeeID is > 0

break;

case 2: // Adding Employee

// @IN-LAB

printf("Adding Employeen");

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

// Check for limits on the array and add employee

// data accordingly.

if (employeesNumber < SIZE) {

printf("nEnter Employee ID: ");

scanf("%d", &emp[counter].id);

printf("Enter Employee Age: ");

scanf("%d", &emp[counter].age);

printf("Enter Employee Salary: ");

scanf("%lf", &emp[counter].salary);

printf("n");

employeesNumber++;

}

else {

printf("ERROR!!! MAXIMUM NUMBER OF EMPLOYEES REACHEDnn");

}

printf("n");

break;

default:

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

}

} while (option != 0);

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

return 0;

}

Business Management, Management Studies

  • Category:- Business Management
  • Reference No.:- M93127898
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Business Management

What is the difference between a heroic leader and a

What is the difference between a heroic leader and a transformational leader and which of the two is best suited to work in today's business world?

Effective human resources professionals have a solid

Effective human resources professionals have a solid understanding of the changing nature of work and the workplace. Compare and contrast the evolution of work and the workplace over the past 20 years and how it has impa ...

Which are five process functional areas of project

Which are five process functional areas of project management framework. Describe main objectives of each functional area and project risk factors face by information technology.

With an emphasis on some of the security ethical and

With an emphasis on some of the security, ethical, and societal challenges of IT in the business world. Please discuss a real-world example/application of an organization that has dealt with crimes including hacking, cyb ...

What should employers consider about compensation and

What should employers consider about compensation and benefits for successful recruitment of talented Gen Xers and millennials?

Stratgeic planningassessment activity cost benefit

STRATGEIC PLANNING ASSESSMENT ACTIVITY: COST BENEFIT ANALYSIS A Sales director is considering whether to implement a new computer based contact management and sales processing system. The Sales directors department has o ...

What would be an appropriate exit strategy for a social

What would be an appropriate "Exit Strategy" for a Social Media Consulting Service adventure using a business finance method?

Questions pertaining to jet bluea give a financial ratio

Questions pertaining to Jet Blue: a. Give a financial ratio analysis for Jet Blue noting good and bad ratios. b. Show Jet Blue's organizational chart found (which I found on Nasdaq (2018). Identify the each chart as well ...

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

With respect to the different environments within an

With respect to the different environments within an organization (certain, risk, or uncertain), why is it best for an organization to support both systematic or mostly intuitive thinkers?

  • 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