This is homework and I'm stumped...the program seems to work except for the last employees gross. The gross should display as 0.0 but shows 334.00 instead. The hour entries are 51.0, 42.5, 37.0, 45.0 and 0.0. Any help is greatly appreciated...I know I'm close but I'm getting cross-eyed at this point.
include <stdio.h>
/ Define Symbolic Constants /
define EMP_NUM 5 / Define number of employees as 5 /
define OT_RATE 1.5 / Define overtime as 1.5 /
define STD_HOURS 40.0 / Define standard time as 40 /
Not be the constant STD_HOURS, but perhaps something like
hours?
A suggestion. You made your hourly rates non-simple numbers.
Now,that may be what the problem asked for, but wheen you are building and debugging code, you are probably better off putting some test numbers, like 10 in, so you see right away if
your calculation is going off.
I actually maade everyone 10.0 for their rate, and plugged in 30,40,50,60,70 for hours to test my correction of your calculation, so I could see the overtime effect kick in.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I understand what you're saying but the program requirements were to use a symbolic constant for the standard hours. Agreed, the logic is off but it seems to work for every employee up until the last employee entry and fails only if that employee has less than 40 hours?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think your analysis is off. It will fail for EVERY employee with less than 40 hours, as it gives credit to every employee for 40 hours, even if they work 0 hours.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey Guys,
This is homework and I'm stumped...the program seems to work except for the last employees gross. The gross should display as 0.0 but shows 334.00 instead. The hour entries are 51.0, 42.5, 37.0, 45.0 and 0.0. Any help is greatly appreciated...I know I'm close but I'm getting cross-eyed at this point.
include <stdio.h>
/ Define Symbolic Constants /
define EMP_NUM 5 / Define number of employees as 5 /
define OT_RATE 1.5 / Define overtime as 1.5 /
define STD_HOURS 40.0 / Define standard time as 40 /
/ Declare Functions /
float collect_Hours (int clock)
{
float hours;
printf("Enter employee hours for clock # %06lu: ", clock);
scanf("%f", &hours);
printf("\n");
return(hours);
}
float calc_Overtime (float hours)
{
if (hours > STD_HOURS)
return (hours - STD_HOURS);
else
return (0.0);
}
float calc_Gross (float hours, float overtime, float wage)
{
float gross;
gross = (STD_HOURS * wage);
void output (int clock, float wage, float hours, float overtime, float gross)
{
printf("\n---------------------------------------------\n");
printf("Clock # Wage Hours OT Gross");
printf("\n---------------------------------------------\n\n");
printf("%06lu %5.2f %3.1f %3.1f %7.2f", clock, wage, hours, overtime, gross);
printf("\n");
}
int main(void)
{
/ Declare Variables /
/ Program Message /
printf("\nThis program will calculate five employees wages.\n\n");
for(entry = 0; entry < EMP_NUM; entry ++)
{
/ Function to get input from user /
}
for(entry = 0; entry < EMP_NUM; entry ++)
{
/ Function to output employee information to the screen /
}
return (0);
}
I figured it out...missing an if else statement in calc_Gross.
Thanks!
I think you need to look at this logic again:
float calc_Gross (float hours, float overtime, float wage)
{
float gross;
gross = (STD_HOURS * wage);
if (overtime > 0)
return (gross + (OT_RATE * wage) * overtime);
else
return gross;
}
It looks to me like you are starting with an assumption that everyone works STD_HOURS, at least in the calculation
Wayne
Might the appropriate variable in:
gross = (STD_HOURS * wage);
Not be the constant STD_HOURS, but perhaps something like
hours?
A suggestion. You made your hourly rates non-simple numbers.
Now,that may be what the problem asked for, but wheen you are building and debugging code, you are probably better off putting some test numbers, like 10 in, so you see right away if
your calculation is going off.
I actually maade everyone 10.0 for their rate, and plugged in 30,40,50,60,70 for hours to test my correction of your calculation, so I could see the overtime effect kick in.
Wayne
Hey Wayne,
I understand what you're saying but the program requirements were to use a symbolic constant for the standard hours. Agreed, the logic is off but it seems to work for every employee up until the last employee entry and fails only if that employee has less than 40 hours?
I think your analysis is off. It will fail for EVERY employee with less than 40 hours, as it gives credit to every employee for 40 hours, even if they work 0 hours.
Wayne
Try plugging in 0 hours for everyone and see what happpens.
Wayne