title: Payroll program in C++
body: <p>I have been working on this program for a class, however I cannot get my output correct.</p>
  <p>My instructions from the assignment are:</p>
  <blockquote>
  <p>Expand the Employee Payroll program to include hourly based and salary based employees. This phase uses an array of employee objects, inheritance for different classes of employees, and polymorphism for salary computation. The 52 week yearly salary as well as number of overtime hours worked by a salary based employee is given).</p>
  <p>For salary based employees, to find the regular (gross) pay for a week, divide the salary by 52. To compute the overtime pay for a salary based employee, first find the hourly rate by dividing the gross pay by 40, and then compute overtime pay. For every employee, overtime pay, tax amount, and net pay must also be computed.</p>
  <p>In addition, the program should find the minimum and maximum net pay of all employees as well as sort the employees based on their net pay (ascending order)</p>
  </blockquote>
  <p>And this is what I have so far:</p>
  <pre><code>#include&lt;fstream&gt;
  #include&lt;iostream&gt;
  #include&lt;iomanip&gt;
  using namespace std;
  int totalEmployeeCount,hrs,employeeCounter,stat,empID;
  double rate,regPay;
  string fName;
  string lName;
  
  class employee{
  public:
  double salary,hourlyRate,taxRate,taxAmount,grossPay,netPay,otPay;
  int hours,otHours;
  
  public: void setVariables(int empID,string fName,string lName, int stat, 
  double rate, double hrs){
      int employeeID = empID;
      string firstName = fName;
      string lastName = lName;
      int payStat = stat;
      if(payStat ==1){hourlyRate = rate;}
      else{salary = rate;}
      hours = hrs;
  }
  //DECLARE FUNCTION TO CALCULATE GROSS PAY
  public: virtual double calculateGrossPay()=0;
  
  double calculateTaxAmount(){ taxRate = .30; // tax rate is a flat rate of 30%
  taxAmount = grossPay*taxRate;  // CALCULATE TAX AMOUNT
  return taxAmount;
  }       // END CALCULATE TAXAMOUNT() FUNCTION.
  
  double calculateNetPay(){
      netPay = grossPay - taxAmount;
      return netPay;
  }       // END CALCULATENETPAY() FUNCTION.
  void printData(){
      cout&lt;&lt;setprecision(2)&lt;&lt;setiosflags(ios::fixed | ios::showpoint);
      cout&lt;&lt;fName&lt;&lt;setw(6)&lt;&lt;lName&lt;&lt;setw(6)&lt;&lt;empID&lt;&lt;setw(10)&lt;&lt;hrs&lt;&lt;setw(3)
      &lt;&lt;otHours&lt;&lt;setw(8)&lt;&lt;grossPay&lt;&lt;setw(8)&lt;&lt;netPay&lt;&lt;setw(8)&lt;&lt;otPay&lt;&lt;endl;}  
  // END PRINTDATA() FUNCTION
  }; // END EMPLOYEE CLASS
  
  class employeeSalary : public employee{
      public: double calculateGrossPay() { 
      double regPay = hours*hourlyRate;
      double hourlyRate = ((salary/52)/40);
      if (hours &gt; 40) {otHours = (hours - 40); //calculate OT hours
       otPay = (otHours * hourlyRate); //calculate OT pay
       grossPay = (regPay + otPay); }
      else if (hours &lt;= 40) {otHours = 0; otPay = 0; grossPay = regPay;}
      return grossPay;    } 
  }; //end EmployeeSalary class 
  
  class employeeHourly : public employee{
    public: double calculateGrossPay(){ 
     regPay = (40 * hourlyRate); //calculate regular hours
    if (hours &gt; 40){   otHours = (hours - 40); //calculate OT hours
       otPay = (otHours * hourlyRate * 1.5); //calculate OT pay
       grossPay = (regPay + otPay); //calculate gross pay
    } //enf if clause for gross pay with overtime
    else { otHours = 0;   otPay = 0; grossPay = regPay;
    } //end else clause for four hours
    return grossPay;  } //end calculateGrossPay() function
  }; //end EmployeeHourly class
  
  int main(){
  int employeeCounter;
  cout&lt;&lt; &quot;enter # of employees you want to process:  &quot;;
  cin&gt;&gt;totalEmployeeCount;
  employee*employee[100];
  while(employeeCounter &lt; totalEmployeeCount){
      cout&lt;&lt;&quot;Is employee &quot;&lt;&lt;employeeCounter+1&lt;&lt; &quot; hourly or salary? (enter 1 
  for hourly / 2 for salary):&quot;;
      cin&gt;&gt;stat;
      if (stat == 1){cout&lt;&lt; &quot;Instantiating and HOURLY employee object 
  inherited from base class employee&quot;
      &lt;&lt;endl&lt;&lt;endl;
          cout&lt;&lt;&quot;Enter employee's ID: &quot;;
          cin&gt;&gt;empID;
          cout&lt;&lt;&quot;Enter employee's first name: &quot;; 
           cin&gt;&gt;fName;
          cout&lt;&lt;&quot;Enter employee's last name: &quot;;
           cin&gt;&gt;lName;
          cout&lt;&lt;&quot;Enter employee's hourly wage: &quot;; 
           cin&gt;&gt;rate;
          cout&lt;&lt;&quot;Enter employee's hours for this week: &quot;; 
           cin&gt;&gt;hrs;
          employee[employeeCounter] = new employeeHourly();         
          employee[employeeCounter]-&gt;setVariables(empID, fName, lName, stat, 
  rate, hrs);
          employee[employeeCounter]-&gt;calculateGrossPay(); 
          employee[employeeCounter]-&gt;calculateTaxAmount(); 
          employee[employeeCounter]-&gt;calculateNetPay();
          cout&lt;&lt;endl&lt;&lt;endl;
              employeeCounter++; } //end if
       
      else{cout&lt;&lt;&quot;instantialting a SALARY employee object in herited from base class employee&quot;
      &lt;&lt;endl&lt;&lt;endl;
      cout&lt;&lt;&quot;Enter employee's ID: &quot;;
          cin&gt;&gt;empID;
          cout&lt;&lt;&quot;Enter employee's first name: &quot;; 
           cin&gt;&gt;fName;
          cout&lt;&lt;&quot;Enter employee's last name: &quot;;
           cin&gt;&gt;lName;
          cout&lt;&lt;&quot;Enter employee's hourly wage: &quot;; 
           cin&gt;&gt;rate;
          cout&lt;&lt;&quot;Enter employee's hours for this week: &quot;; 
           cin&gt;&gt;hrs;
          employee[employeeCounter] = new employeeHourly();         
          employee[employeeCounter]-&gt;setVariables(empID, fName, lName, stat, 
      rate, hrs);
          employee[employeeCounter]-&gt;calculateGrossPay(); 
          employee[employeeCounter]-&gt;calculateTaxAmount(); 
          employee[employeeCounter]-&gt;calculateNetPay();
          cout&lt;&lt;endl&lt;&lt;endl;
          employeeCounter++;}
  }
      /*employeeCounter = 0;
      while (employeeCounter &lt; totalEmployeeCount){
          employee[employeeCounter]-&gt;printData();
          employeeCounter++;
      }*/
  system(&quot;pause&quot;);    
  }
  </code></pre>
  <p>When I run my program in CMD, and input for 2 employees the second employee will overwrite the first one.  I am not sure what is wrong and any help or guidance would be very appreciated (I could not find this asked earlier but I assume it has been, I am a new student and not familiar with Stack Overflow).</p>