Oct 13, 2015 at 6:48am UTC
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 Oct 13, 2015 at 6:55am UTC
Oct 13, 2015 at 7:23am UTC
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 Oct 13, 2015 at 7:26am UTC
Oct 13, 2015 at 7:37am UTC
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 Oct 13, 2015 at 7:45am UTC
Oct 13, 2015 at 9:28am UTC
Per employee:
ordinaryTime
overTime
pay = ( ordinaryTime * normalRate ) + ( overTime * overTimeRate )
So, for all countOfEmployees:
cumulativePay += pay
Finally:
averagePayPerEmployee = cumulativePay / countOfEmployees
Last edited on Oct 13, 2015 at 9:29am UTC