//********************************************************
//
// Assignment 6 - Structures
//
// Name: Seth Hin
//
// Class: C Programming, Spring 2026
//
// Date: March 7, 2026
//
// Description: Program which determines overtime and
// gross pay for a set of employees using an array of
// structures. The program prompts the user for hours
// worked, calculates overtime hours and gross pay,
// and prints the payroll report.
//
// Call by Value design
//
//********************************************************
//-------------------- Includes -------------------------
#include <stdio.h>
#define SIZE 5 // number of employees
#define STD_HOURS 40.0 // standard hours before overtime
#define OT_RATE 1.5 // overtime pay multiplier
//-------------------- Structure Definition ------------------
// Structure to store employee payroll information
struct employee
{
long int clockNumber; // Employee clock number
float wageRate; // Hourly wage rate
float hours; // Hours worked in the week
float overtimeHrs; // Overtime hours worked
float grossPay; // Total gross pay
};
//-------------------- Function Prototypes -------------------
float getHours(long int clockNumber);
float calcOvertime(float hours);
float calcGross(float hours, float wageRate, float overtimeHrs);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
void calcTotals(struct employee empData[], int size,
float *totalWage, float *totalHours,
float *totalOvertime, float *totalGross);
void printTotalsAndAverages(float totalWage, float totalHours,
float totalOvertime, float totalGross,
int size);
//-------------------- Main Function -------------------
int main()
{
// Array of structures to store employee payroll data
struct employee employeeData[SIZE] = {
{98401, 10.60},
{526488, 9.75},
{765349, 10.50},
{34645, 12.25},
{127615, 8.35}
};
int i; // Loop counter
// Loop through each employee to gather hours worked
// and calculate payroll information
for (i = 0; i < SIZE; ++i)
{
// Prompt the user to enter hours worked
employeeData[i].hours = getHours(employeeData[i].clockNumber);
// Calculate overtime hours worked
employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
// Calculate total gross pay including overtime
employeeData[i].grossPay = calcGross(employeeData[i].hours,
employeeData[i].wageRate,
employeeData[i].overtimeHrs);
} // end for (employee payroll calculations)
// Print payroll report header
printHeader();
// Loop through employees and print payroll information
for (i = 0; i < SIZE; ++i)
{
printEmp(employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
} // end for (printing employee data)
// Variables to store totals
float totalWage; // Sum of all employee wage rates
float totalHours; // Total hours worked by all employees
float totalOvertime; // Total overtime hours worked
float totalGross; // Total gross pay for all employees
// Calculate totals for all employees
calcTotals(employeeData, SIZE,
&totalWage, &totalHours,
&totalOvertime, &totalGross);
// Print totals and averages
printTotalsAndAverages(totalWage, totalHours,
totalOvertime, totalGross, SIZE);
return 0; // Program completed successfully
} // end main
//**************************************************************
// Function: getHours
//
// Purpose: Prompts the user to enter hours worked
// for a specific employee.
//
// Parameters:
// clockNumber - unique employee ID
//
// Returns:
// hoursWorked - number of hours worked during the week
//
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked; // Local variable to store user input
// Prompt user for hours worked
printf("\nEnter hours worked by emp # %06li: ", clockNumber
);
// Read input from user
scanf("%f", &hoursWorked
);
return hoursWorked;
} // end getHours
//**************************************************************
// Function: calcOvertime
//
// Purpose: Calculates overtime hours worked by an employee.
//
// Parameters:
// hours - total hours worked during the week
//
// Returns:
// overtime - number of overtime hours worked
//
//**************************************************************
float calcOvertime(float hours)
{
float overtime; // Local variable to store overtime hours
// Determine if employee worked overtime
if (hours > STD_HOURS)
{
overtime = hours - STD_HOURS; // Calculate overtime hours
}
else
{
overtime = 0.0; // No overtime worked
}
return overtime;
} // end calcOvertime
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates the total gross pay including overtime.
//
// Parameters:
// hours - total hours worked
// wageRate - hourly wage rate
// overtimeHrs - overtime hours worked
//
// Returns:
// gross - total gross pay
//
//**************************************************************
float calcGross(float hours, float wageRate, float overtimeHrs)
{
// Calculate regular pay (hours minus overtime)
float regularPay = (hours - overtimeHrs) * wageRate;
// Calculate overtime pay using overtime multiplier
float overtimePay = overtimeHrs * wageRate * OT_RATE;
// Add regular pay and overtime pay to get total gross
float gross = regularPay + overtimePay;
return gross;
} // end calcGross
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the payroll report header.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n");
// Print column headers
printf("\nClock# Wage Hours OT Gross\n"); printf("------------------------------------------------\n");
} // end printHeader
//**************************************************************
// Function: printEmp
//
// Purpose: Prints employee payroll information in a formatted row.
//
// Parameters:
// clockNumber - employee ID
// wageRate - hourly wage
// hours - hours worked
// overtimeHrs - overtime hours
// grossPay - total gross pay
//
// Returns: void
//
//**************************************************************
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
printf("\n %06li %5.2f %5.1f %4.1f %8.2f", clockNumber, wageRate, hours, overtimeHrs, grossPay);
} // end printEmp
//**************************************************************
// Function: calcTotals
//
// Purpose: Calculates totals for wage, hours, overtime,
// and gross pay across all employees.
//
// Parameters:
// empData - array of employee structures
// size - number of employees
// totalWage - pointer storing total wage rate
// totalHours - pointer storing total hours
// totalOvertime - pointer storing total overtime hours
// totalGross - pointer storing total gross pay
//
// Returns: void
//
//**************************************************************
void calcTotals(struct employee empData[], int size,
float *totalWage, float *totalHours,
float *totalOvertime, float *totalGross)
{
int i; // Loop counter
// Initialize totals to zero
*totalWage = 0.0;
*totalHours = 0.0;
*totalOvertime = 0.0;
*totalGross = 0.0;
// Loop through employees and accumulate totals
for (i = 0; i < size; ++i)
{
*totalWage += empData[i].wageRate;
*totalHours += empData[i].hours;
*totalOvertime += empData[i].overtimeHrs;
*totalGross += empData[i].grossPay;
} // end for (totals calculation)
} // end calcTotals
//**************************************************************
// Function: printTotalsAndAverages
//
// Purpose: Prints total and average payroll values.
//
// Parameters:
// totalWage - total wage rate
// totalHours - total hours worked
// totalOvertime - total overtime hours
// totalGross - total gross pay
// size - number of employees
//
// Returns: void
//
//**************************************************************
void printTotalsAndAverages(float totalWage, float totalHours,
float totalOvertime, float totalGross,
int size)
{
// Calculate averages
float avgWage = totalWage / size; // Average wage rate
float avgHours = totalHours / size; // Average hours worked
float avgOvertime = totalOvertime / size; // Average overtime hours
float avgGross = totalGross / size; // Average gross pay
printf("\n------------------------------------------------");
// Print totals
printf("\nTotal %5.2f %5.1f %4.1f %8.2f", totalWage, totalHours, totalOvertime, totalGross);
// Print averages
printf("\nAverage %5.2f %5.1f %4.1f %8.2f\n", avgWage, avgHours, avgOvertime, avgGross);
} // end printTotalsAndAverages