Need help with my avg formula

Wondering why it isn't giving my an average amount,l it worked before i fixed the formula now it's out of wack and giving me a triple digit number

the program is supposed to take input data from an amount of employees ranging from 1-10 and average it from the hourly wage of them + overtime pay

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
   int employees,
       hours;
   double hourlyWage,
          average = 0,
		  overTime = 0;
   
   cout << setprecision(2) << fixed;
   
   cout << "How many employees do you have?" << endl;
   cin >> employees;
   
   while (employees < 1 || employees > 10)
   {
      cout << "Please enter a correct amount of employees 1-10" << endl;
      cin >> employees;
   }
   
   
   for ( int count = 1; count <= employees; count++)
   {
      cout << "How many hours did employee " << count << " work?" << endl;
      cin >> hours;
      cout << "What is the hourly wage of employee " << count << '?' << endl;
      cin >> hourlyWage;
      
      if (hours > 40)
		overTime = (hours - 40) * (hourlyWage * 1.5);
		hourlyWage = overTime;
   }	
      
	  average = average + hourlyWage;
	  average = average/employees;

   cout << "Average is: $" << average << endl;
     
   return 0;
}

I don't know if the issue is occuring with the if statment or with the actual average calculation below it
Last edited on
The if statement on line 33 looks like it should have both of the statements under it enclosed by curly brackets.
Move line 38 to the inside of the line 26 for loop also.
You are neglecting to compute the correct wage as well. (hours * hourlyWage) + overTime
So this would mean line 35 is also wrong because it should be hourlyWage += overTime;
Last edited on
Kevin, how would i fit that wage computation in, would it take the place of line 34?

So far i have this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 for ( int count = 1; count <= employees; average = average + hourlyWage; count++)   
{
      cout << "How many hours did employee " << count << " work?" << endl;
      cin >> hours;
      cout << "What is the hourly wage of employee " << count << '?' << endl;
      cin >> hourlyWage;

      if (hours > 40)
		overTime = (hours - 40) * (hourlyWage * 1.5);
		hourlyWage += overTime;

   
	  average = average/employees;
   }

i'm also getting a large amount of overload function related errors
Last edited on
closed account (48T7M4Gy)
Per employee:
ordinaryTime
overTime
pay = ( ordinaryTime * normalRate ) + ( overTime * overTimeRate )

So, for all countOfEmployees:
cumulativePay += pay

Finally:
averagePayPerEmployee = cumulativePay / countOfEmployees
Last edited on
Topic archived. No new replies allowed.