//********************************************************
//
// Assignment 5 - Employee Pay Calculator
//
// Name: Felix Henriquez
//
// Class: C Programming, Fall 2025
//
// Date: October 12, 2025
//
// Description: Advanced employee pay calculator that determines
// overtime and gross pay with enhanced features and formatting.
//
//********************************************************
#include <stdio.h>
// Constants for business rules
#define MAX_EMPLOYEES 5
#define OVERTIME_RATE 1.5f
#define STANDARD_WORK_WEEK 40.0f
#define COMPANY_NAME "Henriquez Solutions"
// Function prototypes
void displayWelcomeMessage(void);
void getEmployeeHours(float workHours[]);
void computeOvertime(float workHours[], float overtimeHours[]);
void computeGrossPay(float payRate[], float workHours[], float overtimeHours[], float totalPay[]);
void displayPayReport(long int employeeID[], float payRate[], float workHours[],
float overtimeHours[], float totalPay[]);
void displayPaySummary(float totalPay[]);
int main()
{
// Employee database
long int employeeID[MAX_EMPLOYEES] = {98401, 526488, 765349, 34645, 127615};
float payRate[MAX_EMPLOYEES] = {10.60, 9.75, 10.50, 12.25, 8.35};
float workHours[MAX_EMPLOYEES];
float overtimeHours[MAX_EMPLOYEES];
float totalPay[MAX_EMPLOYEES];
// Display welcome message
displayWelcomeMessage();
// Get employee work hours
getEmployeeHours(workHours);
// Calculate payroll components
computeOvertime(workHours, overtimeHours);
computeGrossPay(payRate, workHours, overtimeHours, totalPay);
// Display results
displayPayReport(employeeID, payRate, workHours, overtimeHours, totalPay);
displayPaySummary(totalPay);
printf("\n*** Payroll processing complete! ***\n"); return 0;
}
//**************************************************************
// Function: displayWelcomeMessage
//
// Purpose: Displays a welcome message and company header
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void displayWelcomeMessage(void)
{
printf("\n=================================================="); printf("\n %s", COMPANY_NAME
); printf("\n PAYROLL SYSTEM v2.0"); printf("\n==================================================\n"); printf("\nWelcome to the Employee Pay Calculator!\n"); printf("Please enter the hours worked for each employee.\n"); }
//**************************************************************
// Function: getEmployeeHours
//
// Purpose: Collects hours worked for each employee with validation
//
// Parameters: workHours[] - array to store hours worked
//
// Returns: void
//
//**************************************************************
void getEmployeeHours(float workHours[])
{
int i; // loop counter
printf("\n--------------------------------------------------\n"); printf("ENTER EMPLOYEE HOURS:\n"); printf("--------------------------------------------------\n");
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
printf("Hours for Employee #%d: ", i
+ 1); scanf("%f", &workHours
[i
]);
// Basic validation
if (workHours[i] < 0)
{
printf(" Note: Negative hours entered. Setting to 0.\n"); workHours[i] = 0.0;
}
else if (workHours[i] > 80)
{
printf(" Note: Hours exceed 80. Please verify.\n"); }
}
}
//**************************************************************
// Function: computeOvertime
//
// Purpose: Calculates overtime hours for each employee
//
// Parameters: workHours[] - array of hours worked
// overtimeHours[] - array to store overtime hours
//
// Returns: void
//
//**************************************************************
void computeOvertime(float workHours[], float overtimeHours[])
{
int i; // loop counter
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
if (workHours[i] > STANDARD_WORK_WEEK)
{
overtimeHours[i] = workHours[i] - STANDARD_WORK_WEEK;
}
else
{
overtimeHours[i] = 0.0;
}
}
}
//**************************************************************
// Function: computeGrossPay
//
// Purpose: Calculates total pay including overtime
//
// Parameters: payRate[] - array of hourly pay rates
// workHours[] - array of hours worked
// overtimeHours[] - array of overtime hours
// totalPay[] - array to store gross pay
//
// Returns: void
//
//**************************************************************
void computeGrossPay(float payRate[], float workHours[], float overtimeHours[], float totalPay[])
{
int i; // loop counter
float regularHours; // non-overtime hours
float basePay; // pay for regular hours
float premiumPay; // pay for overtime hours
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
// Determine regular hours (capped at 40)
regularHours = (workHours[i] > STANDARD_WORK_WEEK) ? STANDARD_WORK_WEEK : workHours[i];
// Calculate pay components
basePay = regularHours * payRate[i];
premiumPay = overtimeHours[i] * payRate[i] * OVERTIME_RATE;
// Total compensation
totalPay[i] = basePay + premiumPay;
}
}
//**************************************************************
// Function: displayPayReport
//
// Purpose: Displays detailed pay report in formatted table
//
// Parameters: employeeID[] - array of employee IDs
// payRate[] - array of pay rates
// workHours[] - array of hours worked
// overtimeHours[] - array of overtime hours
// totalPay[] - array of gross pay amounts
//
// Returns: void
//
//**************************************************************
void displayPayReport(long int employeeID[], float payRate[], float workHours[],
float overtimeHours[], float totalPay[])
{
int i; // loop counter
printf("\n================================================================"); printf("\n================================================================"); printf("\n Employee Pay Rate Hours Overtime Gross Pay"); printf("\n------------------------------------------------");
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
printf("\n %06li $%5.2f %5.1f %4.1f $%8.2f", employeeID[i], payRate[i], workHours[i], overtimeHours[i], totalPay[i]);
}
printf("\n================================================================"); }
//**************************************************************
// Function: displayPaySummary
//
// Purpose: Displays payroll summary statistics
//
// Parameters: totalPay[] - array of gross pay amounts
//
// Returns: void
//
//**************************************************************
void displayPaySummary(float totalPay[])
{
int i; // loop counter
float payrollTotal; // sum of all gross pay
float averagePay; // average gross pay
payrollTotal = 0.0;
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
payrollTotal += totalPay[i];
}
averagePay = payrollTotal / MAX_EMPLOYEES;
printf("\n\nPAYROLL SUMMARY:"); printf("\n------------------------------------------"); printf("\nTotal Payroll: $%9.2f", payrollTotal
); printf("\nAverage Pay: $%9.2f", averagePay
); printf("\nEmployees: %d", MAX_EMPLOYEES
); printf("\n------------------------------------------\n"); }