#include <stdio.h>

// Define constants for the program
#define NUM_EMPL 5
#define STD_HOURS 40.0
#define OT_RATE 1.5

// Define a struct for storing employee data
struct employee
{
    long int clockNumber; // employee ID number
    float wageRate; // hourly wage rate
    float hours; // hours worked in a week
    float overtimeHrs; // overtime hours worked in a week
    float grossPay; // gross pay for the week
};

// Declare functions used in the program
float getHours(long int clockNumber); // gets the number of hours worked by an employee
void printHeader(void); // prints a header for the table of employee data
void printEmp(struct employee emp); // prints a row of data for a single employee

int main()
{
    // Declare an array of employee structs and initialize with data
    struct employee employees[NUM_EMPL] = {
        {98401, 10.60},
        {526488, 9.75},
        {765349, 10.50},
        {34645, 12.25},
        {127615, 8.35}
    };

    // Loop through each employee, get their hours worked, and calculate their gross pay
    for (int i = 0; i < NUM_EMPL; ++i)
    {
        employees[i].hours = getHours(employees[i].clockNumber);

        // If the employee worked overtime, calculate the overtime pay
        if (employees[i].hours > STD_HOURS)
        {
            employees[i].overtimeHrs = employees[i].hours - STD_HOURS;
            employees[i].grossPay = STD_HOURS * employees[i].wageRate
                + employees[i].overtimeHrs * employees[i].wageRate * OT_RATE;
        }
        // If the employee did not work overtime, calculate regular pay only
        else
        {
            employees[i].overtimeHrs = 0.0;
            employees[i].grossPay = employees[i].hours * employees[i].wageRate;
        }
    }

    // Print a header for the table of employee data
    printHeader();

    // Loop through each employee and print their data
    for (int i = 0; i < NUM_EMPL; ++i)
    {
        printEmp(employees[i]);
    }

    return 0;
}

// Function to get the number of hours worked by an employee
float getHours(long int clockNumber)
{
    float hoursWorked;

    // Prompt the user to enter the number of hours worked by the employee
    printf("Enter hours worked by emp # %06li: ", clockNumber);
    scanf("%f", &hoursWorked);

    return hoursWorked;
}

// Function to print a header for the table of employee data
void printHeader(void)
{
    printf("\n*** Pay Calculator ***\n\n");
    printf("Clock#   Wage  Hours      OT     Gross\n");
    printf("--------------------------------------\n");
}

// Function to print a row of data for a single employee
void printEmp(struct employee emp)
{
    // Print the employee's ID number, wage rate, hours worked, overtime hours worked, and gross pay
    printf("%06li  %5.2f  %5.1f  %5.1f  %7.2f\n",
           emp.clockNumber, emp.wageRate, emp.hours,
           emp.overtimeHrs, emp.grossPay);
}