title: Incorrect output using structures
body: <p>I am having some trouble displaying data that is in a structure. After the user enters all their information, my program is supposed to display what was entered in the form of ... FirstName LastName TotalPay in the same line. I am testing it out with the hourly workers and their pay, Say there is 3 employees, what is displaying is  the last employees information for 3 times. How can I fix this or what am I doing wrong? </p>
  
  <p>This is my code: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  #include &lt;cctype&gt;
  #include &lt;sstream&gt;
  #include &lt;set&gt;
  #include &lt;iomanip&gt; 
  
  using namespace std;
  
  
  //Create enumeration that contains bonus information 
  enum BonusAvailability{NO_BONUS, AVG_BONUS, HIGH_BONUS};
  
  
  //Create a struct that contains the employees personal information
  struct PersonalInfo
  {
      string fName,
             lName,
             title;
  };
  
  //Create a struct for hourly workers, calls personal info struct 
  struct HourlyW
  {
      PersonalInfo pData ; 
      double hoursWorked; 
      double hourlyRate;
  };
  
  //Create a struct for salary workers, calls personal info struct
  struct SalaryW
  {
      PersonalInfo pData;
      double salary;
      double bonus;
      BonusAvailability bData;
  
  };
  
  
  
  int main()
  {
  
  
      int numInfo; // Holds number of employess to be entered 
      int numHour; // Holds number of hourly workers 
      int numSalary; // Holds number of salary workers
      char selection; // If user wants to continue 
      char selection2; // If user wants to continue 
      double tHour; // Total hourly 
      double tSalary; // Total salary
      HourlyW employee; // Create employee under Hourly W
      SalaryW emp; // Create emp under Salary W
      BonusAvailability b; // Create b under Bonus Availability 
  
                    // Get number of employees to be entered 
                    cout &lt;&lt; "Enter the number of employees you will be entering information for: ";
                    cin &gt;&gt; numInfo;
  
                    // If number is negative, show error message  
                    while (numInfo &lt; 0)
                     {
                         cout &lt;&lt; "Invalid number or negative number! Try again!" &lt;&lt; endl;
                         exit(1);
                     }
                    // Get number of hourly workers     
                    cout &lt;&lt; "How many are hourly workers?" &lt;&lt; endl;
                    cin &gt;&gt;numHour;
  
                    // If number is negative, show error message
                    while (numHour &lt; 0)
                     {
                         cout &lt;&lt; "Invalid number or negative number! Try again!" &lt;&lt; endl;
                         exit(1);
                     }
  
                    // Get number of salary workers 
                    cout &lt;&lt; "How many are salary workers?" &lt;&lt; endl;
                    cin &gt;&gt; numSalary;
  
                    // If number is negative, show error message 
                    while (numSalary &lt; 0)
                     {
                         cout &lt;&lt; "Invalid number or negative number! Try again! " &lt;&lt; endl;
                         exit(1);
                     }
  
                     // If sum of hourly and salary is less than or greater than the total number of employees entered show error message 
                     while ((numHour + numSalary) &gt; numInfo || (numHour + numSalary &lt; numInfo))
                     {
                         cout &lt;&lt; "Hourly workers plus Salary workers does not equal " &lt;&lt; numInfo &lt;&lt; endl;
                         cout &lt;&lt; "Try again " &lt;&lt; endl;
                         cout &lt;&lt; "" &lt;&lt; endl;
                         cout &lt;&lt; "How many hourly workers?" &lt;&lt; endl;
                         cin &gt;&gt;numHour;
                         while (numHour &lt; 0)
                          {
                              cout &lt;&lt; "Invalid number or negative number!" &lt;&lt; endl;
                              exit(1);
                          }
                          cout &lt;&lt; "How many are salary workers?" &lt;&lt; endl;
                          cin &gt;&gt; numSalary;
                          while (numSalary &lt; 0)
                              {
                                  cout &lt;&lt; "Invalid number or negative number!" &lt;&lt; endl;
                                  exit(1);
                              }
                          if (numHour + numSalary == numInfo)
                          {
                              break;
                          }
                     }
  
  
                    // If hourly workers is greater than 0, run this to get the information
                    if (numHour &gt; 0)
                    {
                      cout &lt;&lt; "Hourly Workers!" &lt;&lt; endl;
                      cout &lt;&lt; "---------------" &lt;&lt; endl;
  
                      for (int i = 0; i &lt; numHour; i++)
                      {
  
  
                        cout &lt;&lt; "Enter first name: ";
                        cin &gt;&gt; employee.pData.fName;
                        cout &lt;&lt; "" &lt;&lt; endl;
                        cout &lt;&lt; "Enter last name: ";
                        cin &gt;&gt; employee.pData.lName;
                        cout &lt;&lt; "" &lt;&lt; endl;
                        cout &lt;&lt; "Enter their title: ";
                        cin &gt;&gt; employee.pData.title;
                        cout &lt;&lt; "" &lt;&lt; endl;
                        cout &lt;&lt; "Enter the hours worked: ";
                        cin &gt;&gt; employee.hoursWorked; 
  
                        // If hours worked is less than 0 or greater than 80, show error message 
                        while (employee.hoursWorked &lt; 0 || employee.hoursWorked &gt; 80)
                        {
                            cout &lt;&lt; "Incorrect input!" &lt;&lt; endl;
                            cout &lt;&lt; "" &lt;&lt; endl;
                            cout &lt;&lt; "Enter the hours worked: ";
                            cin &gt;&gt; employee.hoursWorked;
                            if (employee.hoursWorked &gt; 0 || employee.hoursWorked &lt; 80)
                                break;
                        }
                        cout &lt;&lt; "" &lt;&lt; endl;
                        cout &lt;&lt; "Enter the hourly rate: ";
                        cin &gt;&gt; employee.hourlyRate;
                        cout &lt;&lt; "" &lt;&lt; endl;
                        tHour = employee.hoursWorked * employee.hourlyRate; // Get total hourly pay 
  
                        //Ask if they want to continue 
                        cout &lt;&lt; "Would you like to continue? Y or N" &lt;&lt; endl;
                        cin &gt;&gt; selection;
                        if (selection == 'y' || selection == 'Y')
                        {
                            continue;
                        }
                        else 
                        {
                            break;
                        }
                       // cout &lt;&lt; "Total " &lt;&lt; tHour &lt;&lt; endl;  //TEST 
  
  
                      } 
                    }
  
  
                   // If number of salary workers is greater than 0, run this to get the information  
                   if (numSalary &gt; 0)
                   {
                      cout &lt;&lt; "Salary Workers!" &lt;&lt; endl;
                      cout &lt;&lt; "---------------" &lt;&lt; endl;
                      for (int i = 0; i &lt; numSalary; i++)
                      {
  
                          cout &lt;&lt; "Enter first name: ";
                          cin &gt;&gt; emp.pData.fName;
                          cout &lt;&lt; "" &lt;&lt; endl;
                          cout &lt;&lt; "Enter last name: ";
                          cin &gt;&gt; emp.pData.lName;
                          cout &lt;&lt; "" &lt;&lt; endl;
                          cout &lt;&lt; "Enter their title: ";
                          cin &gt;&gt; emp.pData.title;
                          cout &lt;&lt; "" &lt;&lt; endl;
                          cout &lt;&lt; "Enter salary: ";
                          cin &gt;&gt; emp.salary;
  
                          // If salary is less that 0, show error message 
                          while (emp.salary &lt; 0)
                          {
                            cout &lt;&lt; "Incorrect input!" &lt;&lt; endl;
                            cout &lt;&lt; "" &lt;&lt; endl;
                            cout &lt;&lt; "Enter the salary: ";
                            cin &gt;&gt; emp.salary;
                            if (emp.salary &gt; 0)
                                break;
                          }
  
                          cout &lt;&lt;"" &lt;&lt; endl;
                          cout &lt;&lt; "Enter bonus: ";
                          cin &gt;&gt; emp.bonus;
  
                          // If bonus is less than 0, show error message 
                          while (emp.bonus &lt; 0)
                          {
                            cout &lt;&lt; "Incorrect input!" &lt;&lt; endl;
                            cout &lt;&lt; "" &lt;&lt; endl;
                            cout &lt;&lt; "Enter bonus: ";
                            cin &gt;&gt; emp.bonus;
                            if (emp.bonus &gt; 0)
                            {
                              break;
                            }
                          }
  
  
                          tSalary = emp.salary + emp.bonus; // Hold total pay for salary workers 
                          cout &lt;&lt; "Salary is " &lt;&lt; tSalary &lt;&lt; endl; //TEST 
  
                          cout &lt;&lt; "" &lt;&lt; endl;
  
                          //See if user wants to continue 
                          cout &lt;&lt; "Would you like to continue? Y or N" &lt;&lt; endl;
                          cin &gt;&gt; selection2;
                          if (selection2 == 'y' || selection2 == 'Y')
                              {
                                  continue;
                              }
                          else 
                              {
                                  break;
                              }
  
                        // See what category the salary workers fall under 
                        if (emp.bonus == 0)
                        {
                            b = static_cast&lt;BonusAvailability&gt; (0);
  
                        }
                        else if  (emp.bonus &gt; 0 &amp;&amp; emp.bonus &lt;= 5000)
                        {
                            b = static_cast&lt;BonusAvailability&gt; (1);
                        }
                        else if (emp.bonus &gt; 5000)
                        {
                            b = static_cast&lt;BonusAvailability&gt;(2);
                        }
                          cout &lt;&lt; "" &lt;&lt; endl;
                          cout &lt;&lt; "Bonus is " &lt;&lt; b &lt;&lt; endl; //TEST 
                      }
  
                   }
  
                  // Begin displaying information 
                  for (int i = 0; i &lt; numInfo; i++)
                  {
                      cout &lt;&lt; "List of employees" &lt;&lt; endl;
                      cout &lt;&lt; "------------------" &lt;&lt; endl;
                      cout &lt;&lt; employee.pData.fName &lt;&lt; " " &lt;&lt;  employee.pData.lName &lt;&lt; " "    &lt;&lt; tHour &lt;&lt; endl;
                  }
  
  return 0;                
  
  }
  </code></pre>