-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdec8.cpp
More file actions
86 lines (68 loc) · 1.73 KB
/
dec8.cpp
File metadata and controls
86 lines (68 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*#include <iostream>
#include <iomanip>
#include <vector> // To use vectors c++11
// http://www.cplusplus.com/reference/vector/vector/
using namespace std;
int main()
{
vector<int> values = {1, 2, 3};
for(int i = 0; i < values.size(); i++)
cout << values[i] << endl;
return 0;
}*/
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
void enterHours(vector<int>& hours, int numOfEmployees);
void displayHours(vector<int>& hours);
double averageFinder(vector<int>& hours);
int main()
{
int employees;
vector<int> hours;
double average;
cout << "how many employess does your company have: "; cin >> employees;
enterHours(hours, employees);
displayHours(hours);
average = averageFinder(hours);
cout << "The average of hours worked is " << average << "." << endl;
return 0;
}
void displayHours(vector<int>& hours)
{
for(int i = 0; i < hours.size(); i++)
{
cout << "The employee "<< i + 1 << " worked " << hours[i] << " hours."<< endl;
}
}
void enterHours(vector<int>& hours, int numOfEmployees)
{
int tempHours;
for(int i = 0; i < numOfEmployees; i++)
{
cout << "Please enter the hours of the employee " << i + 1 << ": "<< endl;
cin >> tempHours;
hours.push_back(tempHours);
}
}
//Find average
double averageFinder(vector<int>& hours)
{
int total = 0;
double avg = 0.0;
if(hours.empty())
{
cout << "No values to average. ";
avg = 0.0;
}
else
{
for(int count = 0; count < hours.size(); count ++)
{
total += hours[count];
}
avg = total / hours.size();
}
return avg;
}