for loops using arrays, help please!

// This program stores, in an array, the hours worked by
// employees who all make the same hourly wage and then
// prints a list of employee numbers and their gross pay.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int NUM_EMPLOYEES = 5;

int hours[NUM_EMPLOYEES];
double payrate;

// Input the hours worked.

cout << "Enter the hours worked by ";
cout << NUM_EMPLOYEES << " employees\n";
cout << "who all earn the same hourly rate.\n";

// TODO: Write a FOR loop to input hours worked for each employee.
// Use a prompt for each employee that includes the
// employee number. You will need to declare your own loop
// control variable.
// Note: The first location in any array is index 0,
// while the first employee is #1 - be sure to
// account for that in your solution

for (int hours[5], k = 0; k <= 5; k++)
cout << "Employee #: 1" << endl;

// Input the hourly rate for all employees.

cout << "\nEnter the hourly pay rate for all the employees: ";
cin >> payrate;

// Display each employee's gross pay.

cout << "\nHere is the gross pay for each employee:\n";
cout << fixed << showpoint << setprecision(2);

// TODO: Write a FOR loop to calculate the gross pay
// for each employee. The loop should then display
// the employee number and gross pay for each employee.

for (int hours = 0; < NUM_EMPLOYEES; k++)
{
double payrate = hours[40] * payrate;

}

return 0;
}

/* Sample output...

Enter the hours worked by 5 employees
who all earn the same hourly rate.
Employee #1: 40
Employee #2: 38
Employee #3: 40
Employee #4: 35
Employee #5: 20

Enter the hourly pay rate for all the employees: 10.50

Here is the gross pay for each employee:
Employee #1: $420.00
Employee #2: $399.00
Employee #3: $420.00
Employee #4: $367.50
Employee #5: $210.00

*/
Last edited on
Looks like you need a refresher on arrays: http://www.pickinpatchfarm.com/doc/tutorial/arrays/
Registered users can post here. Sign in or register to post.
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22
  • 8109431572 2018-02-22
  • 8757321571 2018-02-22
  • 5265111570 2018-02-22
  • 3351351569 2018-02-22
  • 5109361568 2018-02-22
  • 4455391567 2018-02-22
  • 9091121566 2018-02-22
  • 24791565 2018-02-22
  • 2486841564 2018-02-21
  • 9847231563 2018-02-21
  • 9264681562 2018-02-21