In working on a homework assignment and pretty much have it completed. However, I am having an issue with my first entry every time i use the program. It always gives me a large number for OT and the rest of the outputs are correct. Any thoughts, thanks.
Code:
#include <stdio.h>
#define STD_HOURS 40.0
#define OT_HALF 2.0
//#define NUM_EMP 5.0
int main (void)
{
/* Declare Variables */
int NUM_EMP = 5;
int i = 0; //Accumulator for Loop;
int a = 0; //Accumulator for Arrays;
int clock_num[4]; //Employee Clock Number;
float emp_hours[4]; //Employee Hours;
float emp_wage[4]; //Employee Wage Rate;
float emp_gross[4]; //Employee Total Gross;
float emp_otime[4]; //Employee Over Time;
float ot_acc[4]; //Accumulator for OT;
float ot_wage[4]; //Accumulator for OT Wage;
/* Main Program */
printf("***Gross Pay Calculator***\n");
printf("\n");
/* Begin Employee Input */
for (i = 0; i < NUM_EMP; i++)
{
for (a = 0; a < NUM_EMP; a++)
{
printf("Enter Employee's Clock #:\n");
scanf("%i", &clock_num[a]);
printf("Enter hourly wage:\n");
scanf("%f", &emp_wage[a]);
printf("Enter number of hours worked:\n");
scanf("%f", &emp_hours[a]);
printf("\n");
if (emp_hours[a] > STD_HOURS)
{
ot_wage[a] = emp_wage[a];
ot_wage[a] = ((ot_wage[a] / OT_HALF) + emp_wage[a]);
ot_acc[a] = emp_hours[a] - STD_HOURS;
emp_otime[a] = ot_acc[a] * ot_wage[a];
}
emp_gross[a] = emp_wage[a] * emp_hours[a] + emp_otime[a];
}
/* Display Results */
printf("-----------------------------------------\n");
printf("Clock # Wage Hours OT Gross\n");
printf("-----------------------------------------\n");
for (a = 0; a < NUM_EMP; a++)
{
printf("%06i %5.2f %5.1f %.1f %.2f\n", clock_num[a], emp_wage[a], emp_hours[a], ot_acc[a], emp_gross[a]);
printf("\n");
}
}
}