Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int num_of_employees();
- int days_absent(int);
- double average_days_absent(int, int);
- int input_validation(bool, int);
- int main()
- {
- int total_num_employees = 0, total_days_absent = 0;
- double avg_days_absent = 0.0;
- cout << "Days Out Program" << endl;
- total_num_employees = num_of_employees();
- total_days_absent = days_absent(total_num_employees);
- avg_days_absent = average_days_absent(total_num_employees, total_days_absent);
- cout << showpoint << fixed << setprecision(2);
- cout << "The average number of days absent was " << avg_days_absent << endl;
- return 0;
- }
- int num_of_employees()
- {
- int employees = 0;
- cout << "Enter the number of employees in your company. [1, 2, 3...]: ";
- cin >> employees;
- employees = input_validation(true, employees);
- return employees;
- }
- int days_absent(int total_num_employees)
- {
- int absent = 0, total_absent = 0;
- cout << "Enter the number of days absent for each employee. [0, 1, 2, 3...]: " << endl;
- for (int employees = 1; employees <= total_num_employees; employees++)
- {
- cout << "Employee #" << employees << ": "; cin >> absent;
- absent = input_validation(false, absent);
- total_absent += absent;
- }
- return total_absent;
- }
- double average_days_absent(int total_num_employees, int total_days_absent)
- {
- return (static_cast<double>(total_days_absent) / static_cast<double>(total_num_employees));
- }
- int input_validation(bool is_employees, int input)
- {
- if (is_employees)
- {
- while (input < 1)
- {
- cout << "Number of employees must be at least 1. " << endl;
- cout << "Enter the number of employees in your company. [1, 2, 3...]: ";
- cin >> input;
- }
- }
- else
- {
- while (input < 0)
- {
- cout << "Number of days absent must not be less than 0. " << endl;
- cout << "Enter the number of days absent: " << endl;
- cin >> input;
- }
- }
- return input;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement