//*******************************************************
//
// Assignment 4 - Arrays
//
// Name: <Felix Henriquez>
//
// Class: C Programming, <Fall 2025>
//
// Date: <10/5/2025>
//
// 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()
{
// Declare arrays for employee data
long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
float hours[SIZE]; // hours worked in a given week
float overtimeHrs[SIZE]; // overtime hours worked
float grossPay[SIZE]; // weekly gross pay
// Variables for totals and averages
float totalWage = 0, totalHours = 0, totalOT = 0, totalGross = 0;
float avgWage, avgHours, avgOT, avgGross;
int i; // loop counter
printf("*** Pay Calculator ***\n\n");
// Prompt for hours worked for each employee
for (i = 0; i < SIZE; i++)
{
printf("Enter hours worked for employee %ld: ", clockNumber
[i
]); }
// Calculate overtime and gross pay for each employee
for (i = 0; i < SIZE; i++)
{
// Calculate overtime hours
if (hours[i] > STD_HOURS)
{
overtimeHrs[i] = hours[i] - STD_HOURS;
}
else
{
overtimeHrs[i] = 0;
}
// Calculate gross pay
if (hours[i] <= STD_HOURS)
{
// No overtime - straight pay
grossPay[i] = hours[i] * wageRate[i];
}
else
{
// With overtime - normal pay for 40 hours + OT pay for extra hours
grossPay[i] = (STD_HOURS * wageRate[i]) +
(overtimeHrs[i] * wageRate[i] * OT_RATE);
}
}
// Calculate totals
for (i = 0; i < SIZE; i++)
{
totalWage += wageRate[i];
totalHours += hours[i];
totalOT += overtimeHrs[i];
totalGross += grossPay[i];
}
// Calculate averages
avgWage = totalWage / SIZE;
avgHours = totalHours / SIZE;
avgOT = totalOT / SIZE;
avgGross = totalGross / SIZE;
// Print the header and table
printf("\n-------------------------------------------------------------\n"); printf(" Clock# Wage Hours OT Gross\n"); printf("-------------------------------------------------------------\n");
for (i = 0; i < SIZE; i++)
{
// Print each employee's data with proper formatting
// Clock# with leading zero, wage/hours/OT/gross with proper decimal places
printf(" %06ld %5.2f %4.1f %4.1f %7.2f\n", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
}
// Print the totals line
printf("--------------------------------------------\n"); printf(" Total %5.2f %5.1f %5.1f %8.2f\n", totalWage, totalHours, totalOT, totalGross);
// Print the averages line
printf(" Average %5.2f %5.1f %5.1f %8.2f\n", avgWage, avgHours, avgOT, avgGross);
return 0;
}