thezxtreme

Untitled

Mar 2nd, 2020
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int num_of_employees();
  6. int days_absent(int);
  7. double average_days_absent(int, int);
  8. int input_validation(bool, int);
  9.  
  10. int main()
  11. {
  12. int total_num_employees = 0, total_days_absent = 0;
  13. double avg_days_absent = 0.0;
  14.  
  15. cout << "Days Out Program" << endl;
  16.  
  17. total_num_employees = num_of_employees();
  18. total_days_absent = days_absent(total_num_employees);
  19.  
  20. avg_days_absent = average_days_absent(total_num_employees, total_days_absent);
  21.  
  22. cout << showpoint << fixed << setprecision(2);
  23. cout << "The average number of days absent was " << avg_days_absent << endl;
  24.  
  25. return 0;
  26. }
  27.  
  28. int num_of_employees()
  29. {
  30. int employees = 0;
  31. cout << "Enter the number of employees in your company. [1, 2, 3...]: ";
  32. cin >> employees;
  33.  
  34. employees = input_validation(true, employees);
  35. return employees;
  36. }
  37.  
  38. int days_absent(int total_num_employees)
  39. {
  40. int absent = 0, total_absent = 0;
  41. cout << "Enter the number of days absent for each employee. [0, 1, 2, 3...]: " << endl;
  42.  
  43. for (int employees = 1; employees <= total_num_employees; employees++)
  44. {
  45. cout << "Employee #" << employees << ": "; cin >> absent;
  46. absent = input_validation(false, absent);
  47. total_absent += absent;
  48. }
  49. return total_absent;
  50. }
  51.  
  52. double average_days_absent(int total_num_employees, int total_days_absent)
  53. {
  54. return (static_cast<double>(total_days_absent) / static_cast<double>(total_num_employees));
  55. }
  56.  
  57. int input_validation(bool is_employees, int input)
  58. {
  59. if (is_employees)
  60. {
  61. while (input < 1)
  62. {
  63. cout << "Number of employees must be at least 1. " << endl;
  64. cout << "Enter the number of employees in your company. [1, 2, 3...]: ";
  65. cin >> input;
  66. }
  67. }
  68. else
  69. {
  70. while (input < 0)
  71. {
  72. cout << "Number of days absent must not be less than 0. " << endl;
  73. cout << "Enter the number of days absent: " << endl;
  74. cin >> input;
  75. }
  76. }
  77. return input;
  78. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×