//*******************************************************
//
// Assignment 4 - Arrays
//
// Name: Larson Klipic
//
// Class: C Programming, summer 26
//
// Date: JUN 20th
//
// 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}; 

    printf("\n*** Pay Calculator ***\n\n");
    
    // Process each employee one at a time
    for (i = 0; i < SIZE; i++)
    {
        // FIXED: Changed %lf to %f to match float array, and added missing '&'
        printf("Enter hours worked for employee %06li: ", 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] = wageRate[i] * STD_HOURS;
            // FIXED: Overtime rate must be multiplied by the employee's wage rate
            overtimePay[i] = overtimeHrs[i] * (wageRate[i] * OT_RATE);
        }
        else // no OT
        {
            overtimeHrs[i] = 0;
            overtimePay[i] = 0;
            normalPay[i] = wageRate[i] * hours[i];
        }

        // Calculate Gross Pay
        grossPay[i] = normalPay[i] + overtimePay[i];
    }
    
    // Table Header
    // Spacing formatted to perfectly align with the print statement below
    printf("\n\nClock#   Wage   Hours   Reg-Pay   OT-Hrs   OT-Pay   Gross\n");
    printf("-----------------------------------------------------------------\n");

    // FIXED: Print out all calculated metrics for each employee line by line
    for (i = 0; i < SIZE; i++)
    {
        printf("%06li   %5.2f   %5.1f   %7.2f   %6.1f   %6.2f   %7.2f\n", 
               clockNumber[i], wageRate[i], hours[i], normalPay[i], 
               overtimeHrs[i], overtimePay[i], grossPay[i]);
    }

    return(0);
}