This is the description of what hourly should do: Hourly workers are paid by the hour and allowed to work 20 of hours a week, where they'll receive 100% of their paycheck, but can also work up to 20 additional hours of overtime per month where they'll be paid 125% of their wage (so 20 normal hours, 20 overtime hours)
below is my C code:
#include
int main(void) {
printf("Hello! Please input your worker ID (A = Admin., S = Staff, H = Hourly, J = Adj. Faculty, R = Reg. Faculty, and T = Teaching Assistant) or Q to quit. \n");
char type;
scanf("%c", &type);
int salary = 0;
int overtimeHours = 0;
int hoursWorked = 0;
float hourly = 0.0;
float hAverage = 0;
int hCounter = 0;
float hTotal = 0.0;
while (type != 'q' && type != 'Q'){
switch(type) {
case 'h':
case 'H':
//40 hours a WEEK
overtimeHours = 0;
hoursWorked = 0;
hourly = 0.0;
salary = 0;
puts("Please enter your hourly wage and hours worked.");
scanf(" %f %d", &hourly, &hoursWorked);
hoursWorked = hoursWorked / 4.0;
if (hoursWorked > 40) {
hoursWorked = 20;
overtimeHours = 20;
//for the week
hTotal += 4 *((hoursWorked * hourly)+ (overtimeHours * hourly * 1.25)); //WORKS
hAverage += 4 * (40 * hourly);
}
else if (hoursWorked > 20){
overtimeHours = hoursWorked - 20;
hoursWorked = 20;
hTotal += 4 *((hoursWorked * hourly)+ (overtimeHours * hourly * 1.25));// WORKS
hAverage += 4 * ((hoursWorked) * hourly);
}
else {
hTotal += 4 *((hoursWorked * hourly)+ (overtimeHours * hourly * 1.25)); //WORKS
hAverage += 4 * ((hoursWorked) * hourly);
}
hCounter++;
break;
} //ends switch
puts("Please enter another worker ID, Q for quit, or ? for directions");
scanf(" %c", &type);
} // end while
printf("Hourly %.2f %.2f \n", (hAverage/hCounter), hTotal/hCounter);
return 0;
}//end main
This is only a small portion of the full program. When I only enter one input for hourly it works but with multiple it calculates the wrong input.