I found that and several other errors I am still getting strange output.. I have completed my program but for some reason my "clock" is not passing the correct data.
Code:
#include <stdio.h>
#include <stdlib.h>
#define NUM_EMPL 5
#define OVERTIME_RATE 1.5
#define STD_WORK_WEEK 40.000
struct employee
{
unsigned long int clock; /*clock number*/
float wage; /*hourly pay*/
float hours; /*hours worked*/
float overtime; /*overtime hours above 40*/
float total; /*regular 40 hour pay*/
float gross; /*total pay including any overtime*/
};
void header (void)
{
/* Explain what program is going to do */
printf ("To find out the gross pay of your employees,\n");
printf ("input the hours worked at the clock# prompts.\n");
printf ("\n");
}
void get_input (struct employee emp[])
{
/*Local Variable Declaration */
int count; /* Variable used in loop counter */
/* Loop for number of employees defined in NUM_EMPL */
/* Gets number of employee hours and stores them in an array. */
for (count = 0; count < NUM_EMPL; ++count)
{
printf("Enter Hours for Employee #%06lu: ", emp[count].clock);
scanf ("%f", &emp[count].hours);
}
printf("\n\n\n");
}
void calc_gross (struct employee emp[])
{
/*Local Variable Declaration */
float ot_wage[NUM_EMPL]; /*Variable for overtime wages only */
float total[NUM_EMPL]; /*Variable used to get the total or regular hours before overtime added */
int count; /* Variable used in loop counter */
/* Loop for number of employees defined in NUM_EMPL */
for (count = 0; count < NUM_EMPL; ++count)
/* calculate gross pay including testing for overtime hours using if-else-if statement */
/* use the DEFINE for STD_WORK_WEEK and OVERTIME_RATE*/
/* pull the hours collected from get_input with emp_hours[] array*/
if (emp[count].hours > STD_WORK_WEEK)
{ (emp[count].overtime = emp[count].hours - STD_WORK_WEEK);
(total[count] = emp[count].wage * STD_WORK_WEEK);
(ot_wage[count] = emp[count].wage * OVERTIME_RATE);
(emp[count].gross = ot_wage[count] * emp[count].overtime + total[count]);
}
else if (emp[count].hours <= STD_WORK_WEEK)
{ (emp[count].overtime = 0);
(emp[count].gross = emp[count].wage * emp[count].hours);
}
}
void output_screen (struct employee emp[])
{
/*Local Variable Declaration */
int count; /* Variable used in loop counter */
/*print output in table format using arrays */
printf ("\n");
printf ("__________________________________________________________________________\n");
printf ("Clock #\t\t Wage\t\t Hours\t\t OT\t\tGross Pay\n");
printf ("__________________________________________________________________________\n");
for (count = 0; count < NUM_EMPL; ++count)
{
printf ("%06i4\t\t%7.2f\t\t%7.2f\t\t%7.2f\t\t%7.2f\n", emp[count].clock,
emp[count].wage, emp[count].hours, emp[count].overtime, emp[count].gross);
}
}
/* initialize struct. */
struct employee emp[NUM_EMPL] =
{{98401, 10.60, 0, 0, 0, 0},
{526488, 9.75, 0, 0, 0, 0},
{765349, 10.50, 0, 0, 0, 0},
{34645, 12.25, 0, 0, 0, 0},
{127615, 9.35, 0, 0, 0, 0}};
int main ()
{
struct employee emp[NUM_EMPL];
/* Function to call header. */
header ();
/* Function to call get input using the struct */
get_input(emp);
/* Function call to calculate gross pay including ot using struct*/
calc_gross (emp);
/* Function call to output results to the screen in table format using struct */
output_screen (emp);
system("PAUSE");
return 0;
}