//********************************************************
//
// Assignment 6 - Structures
//
// Name: Seth Hin
//
// Class: C Programming, Spring 2026
//
// Date: March 5, 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);
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 and calculate payroll
for (i = 0; i < SIZE; ++i)
{
// Prompt the user to enter hours worked
employeeData[i].hours = getHours(employeeData[i].clockNumber);
// Calculate overtime hours
employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
// Calculate gross pay
employeeData[i].grossPay = calcGross(employeeData[i].hours,
employeeData[i].wageRate,
employeeData[i].overtimeHrs);
}
// Print payroll report header
printHeader();
// Print each employee's payroll information
for (i = 0; i < SIZE; ++i)
{
printEmp(employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
// Variables to store totals
float totalWage, totalHours, totalOvertime, totalGross;
// Calculate totals
calcTotals(employeeData, SIZE, &totalWage, &totalHours, &totalOvertime, &totalGross);
// Print totals and averages
printTotalsAndAverages(totalWage, totalHours, totalOvertime, totalGross, SIZE);
return 0;
}
//**************************************************************
// Function: getHours
// Purpose: Prompts the user to enter hours worked for an employee
// Parameters: clockNumber - employee ID
// Returns: hours worked (float)
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked; // Local variable for input
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
); return hoursWorked;
}
//**************************************************************
// Function: calcOvertime
// Purpose: Calculates overtime hours
// Parameters: hours - total hours worked
// Returns: overtime hours (float)
//**************************************************************
float calcOvertime(float hours)
{
float overtime; // Local variable to store overtime
if (hours > STD_HOURS)
overtime = hours - STD_HOURS;
else
overtime = 0.0;
return overtime;
}
//**************************************************************
// Function: calcGross
// Purpose: Calculates total gross pay including overtime
// Parameters: hours, wageRate, overtimeHrs
// Returns: gross pay (float)
//**************************************************************
float calcGross(float hours, float wageRate, float overtimeHrs)
{
float regularPay = (hours - overtimeHrs) * wageRate; // Pay for regular hours
float overtimePay = overtimeHrs * wageRate * OT_RATE; // Pay for overtime
float gross = regularPay + overtimePay; // Total gross pay
return gross;
}
//**************************************************************
// Function: printHeader
// Purpose: Prints payroll report header
// Parameters: none
// Returns: void
//**************************************************************
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n"); printf("\nClock# Wage Hours OT Gross\n"); printf("------------------------------------------------\n"); }
//**************************************************************
// Function: printEmp
// Purpose: Prints employee payroll info in formatted columns
// Parameters: clockNumber, wageRate, hours, overtimeHrs, grossPay
// 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);
}
//**************************************************************
// Function: calcTotals
// Purpose: Calculates total wage, hours, overtime, and gross
// Parameters: empData - array of employees, size - number of employees,
// pointers to totals
// Returns: void (totals passed by reference)
//**************************************************************
void calcTotals(struct employee empData[], int size,
float *totalWage, float *totalHours,
float *totalOvertime, float *totalGross)
{
int i; // Loop counter
*totalWage = 0.0;
*totalHours = 0.0;
*totalOvertime = 0.0;
*totalGross = 0.0;
// Loop through employees and sum each column
for (i = 0; i < size; ++i)
{
*totalWage += empData[i].wageRate;
*totalHours += empData[i].hours;
*totalOvertime += empData[i].overtimeHrs;
*totalGross += empData[i].grossPay;
}
}
//**************************************************************
// Function: printTotalsAndAverages
// Purpose: Prints totals and averages of wage, hours, OT, and gross
// Parameters: totalWage, totalHours, totalOvertime, totalGross, size
// Returns: void
//**************************************************************
void printTotalsAndAverages(float totalWage, float totalHours,
float totalOvertime, float totalGross,
int size)
{
float avgWage = totalWage / size; // Average wage
float avgHours = totalHours / size; // Average hours
float avgOvertime = totalOvertime / size; // Average overtime
float avgGross = totalGross / size; // Average gross
printf("\n------------------------------------------------"); printf("\nTotal %5.2f %5.1f %4.1f %8.2f", totalWage, totalHours, totalOvertime, totalGross);
printf("\nAverage %5.2f %5.1f %4.1f %8.2f\n", avgWage, avgHours, avgOvertime, avgGross);
}