
//********************************************************
//
// 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.5f
#define STD_WORK_WEEK 40.0f

// 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() {
    // Variable Declarations
    long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; // ID
    float grossPay[SIZE];   // Gross pay
    float hours[SIZE];      // Hours worked in a given week
    float overtimeHrs[SIZE]; // Overtime hours
    float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35}; // Hourly wage rate
    int i;  // Loop index

    // Process each employee
    for (i = 0; i < SIZE; ++i) {
        hours[i] = getHours(clockNumber[i]);
        overtimeHrs[i] = calculateOvertime(hours[i]);
        grossPay[i] = calculateGrossPay(wageRate[i], hours[i], overtimeHrs[i]);
    }

    // Print the header info
    printHeader();

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

    return 0;
}

// Function to get hours worked from user
float getHours(long int clockNumber) {
    float hoursWorked;
    printf("\nEnter hours worked by emp # %06li: ", clockNumber);
    scanf("%f", &hoursWorked);
    return hoursWorked;
}

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

// Function to print employee details
void printEmp(long int clockNumber, float wageRate, float hours, 
              float overtimeHrs, float grossPay) {
    printf("%06li  %.2f  %.2f  %.2f  %.2f\n", 
           clockNumber, wageRate, hours, overtimeHrs, grossPay);
}

// Function to calculate overtime hours
float calculateOvertime(float hours) {
    return (hours > STD_WORK_WEEK) ? (hours - STD_WORK_WEEK) : 0.0f;
}

// Function to calculate gross pay
float calculateGrossPay(float wageRate, float hours, float overtimeHrs) {
    float regularPay = wageRate * (hours - overtimeHrs);
    float overtimePay = overtimeHrs * (wageRate * OVERTIME_RATE);
    return regularPay + overtimePay;
}