Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void arrayOutput(int array[], int size);
- void arrayTotal(int array[], int size);
- void arrayAverage(int array[], int size);
- int main()
- {
- const int SIZE = 20;
- int employeeHours[SIZE];
- int amountOfEmployees = 0;
- for (int i = 1; i <= SIZE; i++)
- {
- cout << "Enter the amount of hours worked for employee #" << i << ": ";
- cin >> employeeHours[i];
- if (!cin)
- {
- break;
- }
- amountOfEmployees++;
- }
- cout << endl;
- arrayOutput(employeeHours, amountOfEmployees);
- cout << endl;
- arrayTotal(employeeHours, amountOfEmployees);
- arrayAverage(employeeHours, amountOfEmployees);
- cout << endl;
- return 0;
- }
- void arrayOutput(int array[], int size)
- {
- for (int i = 1; i <= size; i++)
- {
- cout << "Employee #" << i << ": " << array[i] << " hour(s).\n";
- }
- }
- void arrayTotal(int array[], int size)
- {
- int totalHours = 0;
- for (int i = 1; i <= size; i++)
- {
- totalHours = totalHours + array[i];
- }
- cout << "Total hours worked: " << totalHours << endl;
- }
- void arrayAverage(int array[], int size)
- {
- int totalHours = 0;
- double arrayAverage;
- for (int i = 1; i <= size; i++)
- {
- totalHours = totalHours + array[i];
- }
- arrayAverage = (totalHours / size);
- cout << "Average of the hours: " << arrayAverage;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement