//********************************************************
//
// Assignment 5 - Functions
//
// Name: <Isaac Boahndao>
//
// Class: C Programming, <Spring Semester and 2025>
//
// Date: <03_02_25>
//
// Description: Program which determines overtime and 
// gross pay for a set of employees with outputs sent 
// to standard output (the screen).
//
// All functions are called by value
//
//********************************************************

#include <stdio.h>

// Constants
#define SIZE 5
#define OVERTIME_RATE 1.5
#define STD_WORK_WEEK 40.0

// 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() {
    // Employee data
    long int clockNumber[SIZE] = {98401, 52648, 76534, 34645, 12761};
    float grossPay[SIZE];
    float hours[SIZE];
    float overtimeHrs[SIZE];
    float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35};
    
    // Process each employee
    for (int i = 0; i < SIZE; i++) {
        // Read hours for employee
        hours[i] = getHours(clockNumber[i]);
        
        // Calculate overtime hours
        overtimeHrs[i] = calculateOvertime(hours[i]);
        
        // Calculate gross pay
        grossPay[i] = calculateGrossPay(wageRate[i], hours[i], overtimeHrs[i]);
    }

    // Print the header info
    printHeader();
    
    // Print all employees
    for (int i = 0; i < SIZE; i++) {
        printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
    }

    return 0;
}

// Function: getHours
// Purpose: Obtains input from user, the number of hours worked per employee and stores the result.
float getHours(long int clockNumber) {
    float hoursWorked;
    printf("Enter hours worked for employee ID %ld: ", clockNumber);
    scanf("%f", &hoursWorked);
    return hoursWorked;
}

// Function: printHeader
// Purpose: Prints the header for the employee summary output
void printHeader(void) {
    printf("\nEmployee Summary:\n");
    printf("---------------------------------------------------------\n");
    printf("Employee ID | Wage Rate | Hours Worked | Overtime Hours | Gross Pay\n");
    printf("---------------------------------------------------------\n");
}

// Function: printEmp
// Purpose: Prints the details for each employee
void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay) {
    printf("%10ld | %9.2f | %12.2f | %14.2f | %9.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
}

// Function: calculateOvertime
// Purpose: Calculates the overtime hours worked
float calculateOvertime(float hours) {
    if (hours > STD_WORK_WEEK) {
        return hours - STD_WORK_WEEK;
    }
    return 0.0;
}

// Function: calculateGrossPay
// Purpose: Calculates the gross pay based on wage rate, hours worked, and overtime
float calculateGrossPay(float wageRate, float hours, float overtimeHrs) {
    float regularPay = wageRate * (hours - overtimeHrs);
    float overtimePay = overtimeHrs * wageRate * OVERTIME_RATE;
    return regularPay + overtimePay;
}