+ 2

Still can't get it to add total.

I need this code to produce the sum of all four weeks wages that I am trying to compute. Am I missing a function to do this? It will produce the last weeks wages correctly, but not the rest and won't add it to the total. //*************************************************** //Determine gross pay for a four-week period based //on hourly rate and number of hours worked each week // with any hours over 40 being paid time-and-a-half //*************************************************** #include <iostream> void calcPay (double, double, double&); //Declaring a function before using & pointer to return const float MAX_HOURS = 40.0; const float OVERTIME = 1.5; using namespace std; int main() { double payRate = 0.0; double wages = 0.0; cout << "Enter pay rate amount:

quot;; cin >> payRate; for(int i=0; i<hours[]; i++) { cout<<"Enter "<<(i+1)<<" week working hours: "; cin >> hours[]; } calcPay(payRate, hours[], wages); cout <<"Wages earned this month are " << wages << "."; return 0; } void calcPay (double payRate, double hours[], double& wages) { if (hours[] > MAX_HOURS) { wages = MAX_HOURS * payRate + (hours[] - MAX_HOURS) * OVERTIME * payRate; } else { wages = hours[] * payRate; } return; } The output is this: Enter pay rate amount: $10 Enter 1 week working hours: 40 Enter 2 week working hours: 40 Enter 3 week working hours: 40 Enter 4 week working hours: 50 Wages earned this month are 550. Process returned 0 (0x0) execution time : 4.446 s Press any key to continue.

28th Nov 2017, 10:06 PM
Elyse Segebart
Elyse Segebart - avatar
1 Respuesta
+ 2
https://code.sololearn.com/c2h472D1xREk/#cpp #include <iostream> double calcWages (bool, double, double); const float MAX_HOURS = 40.0; const float OVERTIME = 1.5; using namespace std; int main() { double payRate = 0.0; double wages = 0.0; double hours = 0.0; cout << "Enter pay rate amount:
quot;; cin >> payRate; cout << payRate << endl; for(int i = 0; i < 4; ++i){ cout << "Enter " << (i+1) << " week working hours: "; cin >> hours; cout << hours << endl; if(hours > MAX_HOURS){ wages += calcWages(true, payRate, hours); } else { wages += calcWages(false, payRate, hours); } } cout << "Wages earned this month are " << wages << "." << endl; return 0; } double calcWages (bool overtime, double payRate, double hours) { if (overtime == true) { return MAX_HOURS * payRate + (hours - MAX_HOURS) * (OVERTIME * payRate); } else { return hours * payRate; } }
29th Nov 2017, 12:12 AM
AgentSmith