//*******************************************************
//
// Assignment 4 - Arrays
//
// Name: Patrick Andrade
//
// Class: C Programming, Fall 2026
//
// Date: September 28, 2026
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
//********************************************************

#include <stdio.h>

// constants to use
#define SIZE 5           // number of employees to process
#define STD_HOURS 40.0   // normal work week hours before overtime
#define OT_RATE 1.5      // time and half overtime setting

int main()
{

    // unique employee identifier
    long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};

    float grossPay [SIZE];     // weekly gross pay - normal pay + overtime pay
    float hours [SIZE];        // hours worked in a given week
    int i;                     // loop and array index
    float normalPay [SIZE];    // normal weekly pay without any overtime
    float overtimeHrs [SIZE];  // overtime hours worked in a given week
    float overtimePay [SIZE];  // overtime pay for a given week

    // hourly pay for each employee
    float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};

    // optional challenge - running totals for each column
    float totalWage = 0;       // sum of all wage rates
    float totalHours = 0;      // sum of all hours worked
    float totalOT = 0;         // sum of all overtime hours
    float totalGross = 0;      // sum of all gross pay

    printf ("\n*** Pay Calculator ***\n\n");

    // Process each employee one at a time
    for (i = 0; i < SIZE; i++)
    {

        // Prompt and read in hours worked for employee
        printf ("Enter the number of hours employee %06li worked: ",
                clockNumber[i]);
        scanf ("%f", &hours[i]);

        // Calculate overtime and gross pay for employee
        if (hours[i] >= STD_HOURS)
        {
            overtimeHrs[i] = hours[i] - STD_HOURS;
            normalPay[i] = STD_HOURS * wageRate[i];
            overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
        }
        else // no OT
        {
            overtimeHrs[i] = 0;
            normalPay[i] = hours[i] * wageRate[i];
            overtimePay[i] = 0;
        }

        // Calculate Gross Pay
        grossPay[i] = normalPay[i] + overtimePay[i];

        // optional challenge - add this employee to the totals
        totalWage += wageRate[i];
        totalHours += hours[i];
        totalOT += overtimeHrs[i];
        totalGross += grossPay[i];
    }

    // Print a nice table header
    printf ("\n");
    printf ("---------------------------------------------\n");
    printf ("  Clock#    Wage   Hours     OT      Gross\n");
    printf ("---------------------------------------------\n");

    // Now that we have all the information in our arrays, we can
    // access each employee and print to screen
    for (i = 0; i < SIZE; i++)
    {
        printf ("  %06li  %6.2f  %6.1f  %5.1f  %9.2f\n",
                clockNumber[i], wageRate[i], hours[i],
                overtimeHrs[i], grossPay[i]);
    }

    // optional challenge - print totals and averages
    printf ("---------------------------------------------\n");
    printf ("  Total   %6.2f  %6.1f  %5.1f  %9.2f\n",
            totalWage, totalHours, totalOT, totalGross);
    printf ("  Average %6.2f  %6.1f  %5.1f  %9.2f\n",
            totalWage / SIZE, totalHours / SIZE,
            totalOT / SIZE, totalGross / SIZE);

    return(0);
}