//********************************************************
//
// Assignment 6 - Employee Pay Calculator with Structures
//
// Name: Felix Henriquez
//
// Class: C Programming, Fall 2025
//
// Date: October 19, 2025
//
// Description: Employee pay calculator using structures
// to determine overtime and gross pay.
//
//********************************************************
#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"
// Structure definition
struct employee
{
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
// Function prototypes
void displayWelcomeMessage(void);
void getEmployeeHours(struct employee employees[]);
void computeOvertime(struct employee employees[]);
void computeGrossPay(struct employee employees[]);
void displayPayReport(struct employee employees[]);
void displayPaySummary(struct employee employees[]);
void calculateTotals(struct employee employees[], float totals[], float averages[]);
int main()
{
// Initialize array of structures
struct employee employees[MAX_EMPLOYEES] = {
{98401, 10.60, 0, 0, 0},
{526488, 9.75, 0, 0, 0},
{765349, 10.50, 0, 0, 0},
{34645, 12.25, 0, 0, 0},
{127615, 8.35, 0, 0, 0}
};
// Display welcome message
displayWelcomeMessage();
// Get employee work hours
getEmployeeHours(employees);
// Calculate payroll components
computeOvertime(employees);
computeGrossPay(employees);
// Display results
displayPayReport(employees);
displayPaySummary(employees);
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 v3.0 (Structures)"); 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: employees[] - array of employee structures
//
// Returns: void
//
//**************************************************************
void getEmployeeHours(struct employee employees[])
{
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 (Clock# %06ld): ", i
+ 1, employees
[i
].
clockNumber); scanf("%f", &employees
[i
].
hours);
// Basic validation
if (employees[i].hours < 0)
{
printf(" Note: Negative hours entered. Setting to 0.\n"); employees[i].hours = 0.0;
}
else if (employees[i].hours > 80)
{
printf(" Note: Hours exceed 80. Please verify.\n"); }
}
}
//**************************************************************
// Function: computeOvertime
//
// Purpose: Calculates overtime hours for each employee
//
// Parameters: employees[] - array of employee structures
//
// Returns: void
//
//**************************************************************
void computeOvertime(struct employee employees[])
{
int i; // loop counter
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
if (employees[i].hours > STANDARD_WORK_WEEK)
{
employees[i].overtimeHrs = employees[i].hours - STANDARD_WORK_WEEK;
}
else
{
employees[i].overtimeHrs = 0.0;
}
}
}
//**************************************************************
// Function: computeGrossPay
//
// Purpose: Calculates total pay including overtime
//
// Parameters: employees[] - array of employee structures
//
// Returns: void
//
//**************************************************************
void computeGrossPay(struct employee employees[])
{
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 = (employees[i].hours > STANDARD_WORK_WEEK) ? STANDARD_WORK_WEEK : employees[i].hours;
// Calculate pay components
basePay = regularHours * employees[i].wageRate;
premiumPay = employees[i].overtimeHrs * employees[i].wageRate * OVERTIME_RATE;
// Total compensation
employees[i].grossPay = basePay + premiumPay;
}
}
//**************************************************************
// Function: displayPayReport
//
// Purpose: Displays detailed pay report in formatted table
//
// Parameters: employees[] - array of employee structures
//
// Returns: void
//
//**************************************************************
void displayPayReport(struct employee employees[])
{
int i; // loop counter
float totals[5] = {0}; // wage, hours, OT, gross
float averages[5] = {0};
// Calculate totals and averages
calculateTotals(employees, totals, averages);
printf("\n--------------------------------------------------------------------------"); printf("\n Clock# Wage Hours OT Gross"); printf("\n--------------------------------------------------------------------------");
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
printf("\n %06ld %5.2f %5.1f %4.1f %8.2f", employees[i].clockNumber,
employees[i].wageRate,
employees[i].hours,
employees[i].overtimeHrs,
employees[i].grossPay);
}
// Display separator line
printf("\n--------------------------------------------------------------------------");
// Display totals
printf("\n Total %5.2f %5.1f %4.1f %8.2f", totals[0], totals[1], totals[2], totals[3]);
// Display averages
printf("\n Average %5.2f %4.1f %3.1f %8.2f", averages[0], averages[1], averages[2], averages[3]);
printf("\n--------------------------------------------------------------------------"); }
//**************************************************************
// Function: calculateTotals
//
// Purpose: Calculates totals and averages for the report
//
// Parameters: employees[] - array of employee structures
// totals[] - array to store totals
// averages[] - array to store averages
//
// Returns: void
//
//**************************************************************
void calculateTotals(struct employee employees[], float totals[], float averages[])
{
int i; // loop counter
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
totals[0] += employees[i].wageRate; // Sum of wages
totals[1] += employees[i].hours; // Sum of hours
totals[2] += employees[i].overtimeHrs; // Sum of overtime
totals[3] += employees[i].grossPay; // Sum of gross pay
}
// Calculate averages
for (i = 0; i < 4; ++i)
{
averages[i] = totals[i] / MAX_EMPLOYEES;
}
}
//**************************************************************
// Function: displayPaySummary
//
// Purpose: Displays payroll summary statistics
//
// Parameters: employees[] - array of employee structures
//
// Returns: void
//
//**************************************************************
void displayPaySummary(struct employee employees[])
{
float payrollTotal = 0.0;
float totalHours = 0.0;
float totalOvertime = 0.0;
int i;
for (i = 0; i < MAX_EMPLOYEES; ++i)
{
payrollTotal += employees[i].grossPay;
totalHours += employees[i].hours;
totalOvertime += employees[i].overtimeHrs;
}
printf("\n\nPAYROLL SUMMARY:"); printf("\n------------------------------------------"); printf("\nTotal Gross Pay: $%9.2f", payrollTotal
); printf("\nAverage Gross Pay: $%9.2f", payrollTotal
/ MAX_EMPLOYEES
); printf("\nTotal Hours: %9.1f", totalHours
); printf("\nOvertime Hours: %9.1f", totalOvertime
); printf("\nEmployees Processed:%9d", MAX_EMPLOYEES
); printf("\n------------------------------------------\n"); }