Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void arrayOutput(int array[], int size);
  5. void arrayTotal(int array[], int size);
  6. void arrayAverage(int array[], int size);
  7.  
  8. int main()
  9. {
  10.     const int SIZE = 20;
  11.     int employeeHours[SIZE];
  12.     int amountOfEmployees = 0;
  13.  
  14.     for (int i = 1; i <= SIZE; i++)
  15.     {
  16.         cout << "Enter the amount of hours worked for employee #" << i << ": ";
  17.         cin >> employeeHours[i];
  18.         if (!cin)
  19.         {
  20.             break;
  21.         }
  22.         amountOfEmployees++;
  23.     }
  24.     cout << endl;
  25.     arrayOutput(employeeHours, amountOfEmployees);
  26.     cout << endl;
  27.     arrayTotal(employeeHours, amountOfEmployees);
  28.     arrayAverage(employeeHours, amountOfEmployees);
  29.     cout << endl;
  30.  
  31.     return 0;
  32. }
  33.  
  34. void arrayOutput(int array[], int size)
  35. {
  36.     for (int i = 1; i <= size; i++)
  37.     {
  38.         cout << "Employee #" << i << ": " << array[i] << " hour(s).\n";
  39.     }
  40. }
  41.  
  42. void arrayTotal(int array[], int size)
  43. {
  44.     int totalHours = 0;
  45.  
  46.     for (int i = 1; i <= size; i++)
  47.     {
  48.         totalHours = totalHours + array[i];
  49.     }
  50.  
  51.     cout << "Total hours worked: " << totalHours << endl;
  52. }
  53.  
  54. void arrayAverage(int array[], int size)
  55. {
  56.     int totalHours = 0;
  57.     double arrayAverage;
  58.  
  59.     for (int i = 1; i <= size; i++)
  60.     {
  61.         totalHours = totalHours + array[i];
  62.     }
  63.  
  64.     arrayAverage = (totalHours / size);
  65.     cout << "Average of the hours: " << arrayAverage;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement