2 Attachment(s)
C++ Formula Error - Confusing Output
I have attached the c++ code file and the header file I'm using to compile it.
The program has to take in employee details, and work out a wage slip from there.
The problem is from line 112 - 120, when the hours & overtime must be entered together.
Any hours over 37.5 need to be separated and declared as a separate variable. Then multiplied by the rate of pay. The variables must be declared separately because they are both used separately, they go on to multiply by separate rate of pay, the output for this is also spewed out like garbage! Apart from that the program runs fine and put out all the right figures.
Any help will be greatly appreciated!
if ( customers[row].hours < 37.5 )
{
customers[row].ohours = customers[row].hours - 37.5;
customers[row].hours = 37.5;
}
else if (customers[row].hours > 37.5 )
{
customers[row].hours = customers[row].hours;
customers[row].ohours = 0;
}
Re: C++ Formula Error - Confusing Output
I didn't look at your attachments, but ...
say 40 hours are worked ... what will your code calculate for
ohours and hours ?
Also, what if the number of hours is exactly 37.5 ?
Re: C++ Formula Error - Confusing Output
if 40 hours are worked, it should calculate 37.5 at normal rate and 2.5 at overtime rate of time and a half.
if 37.5 hours are worked it should just calculate 37.5 * rate. However if 38 are worked, 0.5 hours should be paid at the overtime rate.
Re: C++ Formula Error - Confusing Output
I'm thinking you should examine your use of < and >
Re: C++ Formula Error - Confusing Output
Didn't even notice that! Silly error.
Corrected it:-
if ( customers[row].hours >= 37.5 )
{
customers[row].ohours = customers[row].hours - 37.5;
customers[row].hours = 37.5;
}
else if (customers[row].hours < 37.5 )
{
customers[row].hours = customers[row].hours;
customers[row].ohours = 0;
}
But there still seems to be some problem with the calculations in the next few line and im getting -1.07374e+008 out of both calculations.
customers[row].rateo = (customers[row].rate*1.5);
customers[row].spay = (customers[row].hours*customers[row].rate);
customers[row].opay = (customers[row].ohours*customers[row].rateo);
rate being the input value per hour
and rateo being the overtime value at time+1/2.
Re: C++ Formula Error - Confusing Output
Look at all the values in your calculation and figure out which one doesn't make sense. Your debugger will help.
Re: C++ Formula Error - Confusing Output
i was passing [row] instead of [r]. [row] is an empty field!