Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Didn\'t get an answer. This is for C++, BTW. ese two pieces of code are causing

ID: 3573093 • Letter: D

Question

Didn't get an answer. This is for C++, BTW.

ese two pieces of code are causing a problem. employeeNames[0] is being overwritten with employeeNames[1] in terms of where it pops out (employeeNames[0] doesn't show up at all after initial viewing), however this error does not occur anywhere else, and when viewing just employeeNames[0], it is properly showing up. When I add employeeNames[3] and employeeNames[4], they are properly being displayed, and in their proper position.

void addEmployee1()
{
   system("cls");
   cout << "Employee Payroll Calculation" << endl;
   cout << endl;
   cout << "Add Employee" << endl;
   cout << endl;
   cout << "Employee Name: ";
   cin.ignore(1, '/ n');
   getline(cin, employeeNames[0]);
   cout << endl;
   cout << "Employee Withholding: ";
   cin >> employeesWithhold[0];
}

void addEmployee2()
{
   system("cls");
   cout << "Employee Payroll Calculation" << endl;
   cout << endl;
   cout << "Add Employee" << endl;
   cout << endl;
   cout << "Employee Name: ";
   cin.ignore(1, '/ n');
   getline(cin, employeeNames[1]);
   cout << endl;
   cout << "Employee Withholding: ";
   cin >> employeesWithhold[1];

}

void editEmployeeList() //This is the function for the list of employees for editting.
{
   system("cls");
   cout << "Employee Payroll Calculation" << endl;
   cout << endl;
   cout << "Edit Employee" << endl;
   cout << endl;
   if (employeeCount == 1) // This is gonna repeat. Best way I could figure it out to only display the correct employee count!
   {
       cout << "1. " << employeeNames[0] << endl;
       if (internalEmployeeCount = 0)
       {
           internalEmployeeCount++;
       }
   }
   else if (employeeCount == 2)
   {
       cout << "1. " << employeeNames[0] << endl;
       cout << "2. " << employeeNames[1] << endl;
       if (internalEmployeeCount = 1)
       {
           internalEmployeeCount++;
       }
   }

Explanation / Answer

correction 1

In your program,the if statement which I have shown below should be written as

if (internalEmployeeCount == 0)

instead of   

if (internalEmployeeCount = 0)

because inside if we always perform comparison,not assignment.your code will assign internalEmployeeCount=0 ,so that vallriable becomes 0.do the corrections as I have shown above .

correction 2

same as above

write  

if (internalEmployeeCount == 1)

instead of  

if (internalEmployeeCount = 1)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote