Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int employeeAmount, employeeAmountCounter;
  7. int employeeNumber, daysAbsent;
  8. int totalDaysAbsent, averageDaysAbsent;
  9. //double totalDaysAbsent2, averageDaysAbsent2;
  10. ofstream outputFile;
  11.  
  12. void numberOfEmployees()
  13. {
  14. cout << "How many employees are in the company? ";
  15. }
  16.  
  17.  
  18. int employeeInformation(int &employeeNumber, int &daysAbsent, int &employeeAmountCounter, int totalDaysAbsent)
  19. {
  20. for (employeeAmountCounter = 0; employeeAmountCounter < employeeAmount; employeeAmountCounter++)
  21. {
  22. cout << "What is the employee's number?" << endl;
  23. cin >> employeeNumber;
  24. cout << "How many days was this employee absent?" << endl;
  25. cin >> daysAbsent;
  26.  
  27. totalDaysAbsent += daysAbsent;
  28. employeeAmountCounter++;
  29.  
  30. outputFile << employeeNumber << "\t\t" << daysAbsent;
  31. }
  32.  
  33. return(totalDaysAbsent);
  34. }
  35.  
  36. double averageDaysAbsentFunction(int totalDaysAbsent, int employeeAmount, double averageDaysAbsent)
  37. {
  38. averageDaysAbsent = totalDaysAbsent / employeeAmount;
  39. return (averageDaysAbsent);
  40. }
  41.  
  42. int main()
  43. {
  44. cout << "This program will calculate the average number of days each employee is absent." << endl;
  45. numberOfEmployees();
  46. cin >> employeeAmount;
  47.  
  48. while (employeeAmount < 1)
  49. {
  50. cout << "\nInvalid entry. Please enter a new amount for the number of employees" << endl;
  51. cout << "that is greater than or equal to 1." << endl;
  52. cin >> employeeAmount;
  53. }
  54.  
  55. outputFile.open("employeeAbsences.txt");
  56. outputFile << "EMPLOYEE ABSENCES REPORT\n";
  57.  
  58. employeeInformation(employeeNumber, daysAbsent, employeeAmount, employeeAmountCounter);
  59.  
  60. averageDaysAbsentFunction(totalDaysAbsent, employeeAmount, averageDaysAbsent);
  61.  
  62. outputFile << "-------------------------------------------------------------------------------------";
  63. outputFile << employeeAmount << " employees were absent for a total of ";
  64. outputFile << totalDaysAbsent << " days.\n";
  65. outputFile << "The average number of days absent is ";
  66. outputFile << setprecision(1) << showpoint << fixed << averageDaysAbsent << " days.\n";
  67. outputFile << "Programmer:\t Amanda Yoresh";
  68. outputFile << "-------------------------------------------------------------------------------------";
  69. outputFile.close();
  70. system("pause");
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement