### 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/

### Forum

• 629832435 2018-04-20
• 4254782434 2018-04-20
• 7642392433 2018-04-20
• 4201592432 2018-04-20
• 1221362431 2018-04-20
• 5455692430 2018-04-20
• 8345962429 2018-04-20
• 7297372428 2018-04-20
• 4929522427 2018-04-20
• 1938132426 2018-04-20
• 2267862425 2018-04-20
• 6177082424 2018-04-20
• 838232423 2018-04-20
• 4694502422 2018-04-20
• 6512882421 2018-04-19
• 4659652420 2018-04-19
• 2967832419 2018-04-19
• 8339042418 2018-04-19
• 8147112417 2018-04-19
• 2774752416 2018-04-19