#include <stdio.h>

// Define Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5

// Define a global structure to store employee data
struct employee
{
    long int clockNumber;
    float wageRate;
    float hours;
    float overtimeHrs;
    float grossPay;
};

// Function prototypes
float getHours(long int clockNumber);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
              float overtimeHrs, float grossPay);
float calculateOvertime(float hours);
float calculateGrossPay(float wageRate, float hours, float overtimeHrs);

int main()
{
    // Initialize the array of employee data
    struct employee employeeData[SIZE] = {
        {98401, 10.60},
        {526488, 9.75},
        {765349, 10.50},
        {34645, 12.25},
        {127615, 8.35}
    };

    int i;

    // Loop to process each employee's data
    for (i = 0; i < SIZE; ++i)
    {
        // Prompt for the number of hours worked by the employee
        employeeData[i].hours = getHours(employeeData[i].clockNumber);

        // Calculate overtime hours
        employeeData[i].overtimeHrs = calculateOvertime(employeeData[i].hours);

        // Calculate gross pay
        employeeData[i].grossPay = calculateGrossPay(employeeData[i].wageRate,
                                                     employeeData[i].hours,
                                                     employeeData[i].overtimeHrs);
    }

    // Print the table header
    printHeader();

    // Print out each employee's data
    for (i = 0; i < SIZE; ++i)
    {
        printEmp(employeeData[i].clockNumber,
                 employeeData[i].wageRate,
                 employeeData[i].hours,
                 employeeData[i].overtimeHrs,
                 employeeData[i].grossPay);
    }

    return 0; // success
}

//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from the user for the number of hours
// worked by an employee.
//
// Parameters: clockNumber - The unique employee ID
//
// Returns: The hours worked by the employee
//**************************************************************
float getHours(long int clockNumber)
{
    float hoursWorked;

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

    return hoursWorked;
}

//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//**************************************************************
void printHeader(void)
{
    printf("\n\n*** Pay Calculator ***\n");
    printf("\nClock#   Wage  Hours  OT     Gross\n");
    printf("-----------------------------------------\n");
}

//*************************************************************
// Function: printEmp
//
// Purpose: Prints out an employee's information in a formatted table.
//
// Parameters:
//     clockNumber - Employee ID
//     wageRate - Employee's wage rate
//     hours - Total hours worked
//     overtimeHrs - Overtime hours worked
//     grossPay - Gross pay for the employee
//
// Returns: void
//*************************************************************
void printEmp(long int clockNumber, float wageRate, float hours,
              float overtimeHrs, float grossPay)
{
    printf("%06li   %5.2f  %4.1f   %4.1f   %8.2f\n",
           clockNumber, wageRate, hours, overtimeHrs, grossPay);
}

//**************************************************************
// Function: calculateOvertime
//
// Purpose: Calculates overtime hours. Anything over 40 hours is overtime.
//
// Parameters: hours - Total hours worked by the employee
//
// Returns: overtime hours
//**************************************************************
float calculateOvertime(float hours)
{
    if (hours > STD_HOURS)
        return hours - STD_HOURS; // Overtime hours
    return 0.0;
}

//**************************************************************
// Function: calculateGrossPay
//
// Purpose: Calculates gross pay (normal pay + overtime pay).
//
// Parameters:
//     wageRate - Employee's hourly wage rate
//     hours - Total hours worked
//     overtimeHrs - Overtime hours worked
//
// Returns: gross pay (normal pay + overtime pay)
//**************************************************************
float calculateGrossPay(float wageRate, float hours, float overtimeHrs)
{
    float normalPay = wageRate * (hours - overtimeHrs);
    float overtimePay = overtimeHrs * wageRate * OT_RATE;
    return normalPay + overtimePay;
}