I'm working on a payroll program and I'm having problems that are causing calculation errors.
_____________________________________________________________________________
My input file is
1234 Fred Jones 40 25.00
2345 Terry Smith 60 10.00
_____________________________________________________________________________
The errors I get are from the regular pay, over time pay, gross pay, tax amount
and net pay calculations. They all look similar to this (6e+002). I believe they are occurring because regular pay isn't calculating correctly and the rest depend on that for their calculations. However, I can't see why regular pay isn't calculating correctly. Anyone see what I'm missing?
_____________________________________________________________________________
void payroll::calculategrosspay(){
if (hoursworked > 40){
overtimehours = hoursworked - 40;
regularpay = 40 * hourlyrate;//Modified to be 40 flat for max regular hours;
overtimepay = overtimehours * (hourlyrate * 1.5);
grosspay = regularpay + overtimepay;
}//IF
else
{
overtimehours= 0;//Implemented to ensure default value;
regularpay = hoursworked * hourlyrate;
overtimepay = 0;//Implemented to ensure default value;
grosspay = regularpay;//gross pay = regular pay?
}
}//CALCULATEGROSSPAY
-SMALL BUSINESS PAYROLL REPORT-
-------------------------------------------------------------------
EMPLOYEE ID FIRST NAME LAST NAME HW HR OTH RP OTP
GP TAX AMT NET PAY
---------------------------------------------------------------------
1234 Fred Jones 40 25 0 1e+003 0 1
e+003 3e+002 7e+002
2345 Terry Smith 60 10 20 4e+002 3e+002 7
e+002 2.1e+002 4.9e+002
Regular pay for Fred: 1e+003 == 1000 == 40*25;
Regular pay for Terry: 4e+002 == 400 == 400 == 10*40
Edited to provide some details...
Edit, it looks correct to me, maybe you aren't sure what you should be expecting.
hmmm...tried adding that and it changed basically nothing I still have error numbers in all the same spots the errors are just different now. 4e+002 for example rather then the 6e+002. I know it's a calculation error but I'll got no idea why it's happening at the moment.
-SMALL BUSINESS PAYROLL REPORT-
-------------------------------------------------------------------
EMPLOYEE ID FIRST NAME LAST NAME HW HR OTH RP OTP
GP TAX AMT NET PAY
---------------------------------------------------------------------
1234 Fred Jones 40 25 0 1000.00 0.00 10
00.00 300.00 700.00
2345 Terry Smith 60 10.00 20 400.00 300.00 7
00.00 210.00 490.00
Yeah your explanation is very helpful and I understand that things like 4e+002 represent/link different values thanks to you (which is a good learning experience in itself.) I just still have to figure out how to get them back to looking like 400.00, 300.00 and 1000.00. Then I have some more things to do with the program before it's finished.
:)
I'm not much of a programer and some of the things people on this forum help out with are really amazing. I hope it gets easier with practice because right now it's more long hours and headaches.
<< fixed before the data will set the output to your liking; 400.00.
Example:<< setw(8) << fixed << regularpay //stuff
After using code, a dozen or so times, it'll become habitual; second nature.
Tip:
Focus on design, not syntax, and refer to online documentations or your text books for syntax when needed. Slowly decrease the number of reference to syntax, that you use a lot, and you'll eventually find yourself remembering small pieces of code.
When under deadlines and stress, you can find yourself using code.
When not, you'll find yourself learning code.
Thanks! with the <<fixed added to it's back to regular numerical values!
I think I've got this program just about wrapped up but I have one more calculation related error going on. This time it's related to finding the net pay average for all the employee's in my input file.
I think I have this just about worked out but I'm getting an error that looks like this
1 error C4716: 'payroll::findavg' : must return a value
Ok so I can wrap my head around the idea that the error is occurring because I haven't constructed my means of finding the average correctly. Can you give me any advice on how I can go about returning a value so that it calculates correctly?
Can I change/add to the code to make it work and calculate?
1 2 3 4
double payroll::findavg(double sum, int i){
average = sum / i;
cout << endl << "The netpay average is " << average << endl;
}//FIND AVERAGE
You'd put a return statement at the end of the calculation.
1 2 3 4 5
double payroll::findavg(double sum, int i){
average = sum / i;
cout << endl << "The netpay average is " << average << endl;
return average; // <- return statement here
}//FIND AVERAGE
The calling function would then need a way to hold the value returned from the function if you were going to use it again. avg = findavg(sum, i);
But since this function prints out the average - do you need the function to return the value of the average or can it be another void function?
ha thanks I've been fooling around with this for awhile now and I added the line return average just before checking back here to see your post wildblue! Sometimes I seem to miss the forest for the trees. It was a pretty simple fix when I was thinking it was something else.