thank you, after 4 hours trying to get it to work i came up with this:
Might not be the best way to do it but it worked. What would be the easiest way?
//Steven Calabrese
//Lab 4 Calculate gross pay
//Displays Gross Pay using a decision and 2 decimal places
//10/21/13
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
You could make the variables reghours and overhours local to calcPay() rather than main() and do the calcs. there instead. Then you are passing only hours and rate to the calcPay().
No. I meant to do all the calcs in calcPay. Sorry if I worded that poorly.
1 2 3 4 5 6 7 8
double calcPay (double hours, double rate)
{
double pay=0.0, overhours=0.0, reghours=0.0;// or other suitable initial values?
// all calcs here
return pay;
}
EDIT: Although your approach with the overhours and reghours variables word work I think it's more complicated than necessary. I would:
1) initialize pay as though all hours are paid at rate.
2) add the OT premium to pay for hours over 40.
This gives 3 lines of code in calcPay, with no reghours or overhours variables involved.