//********************************************************
//
// 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>
//-------------------- Constants ------------------------
#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 used 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);
int main ()
{
// Array of structures to store employee payroll data
struct employee employeeData[SIZE] = {
{ 98401, 10.60 },
{ 526488, 9.75 },
{ 765349, 10.50 }, // initialize clock numbers and wages
{ 34645, 12.25 },
{ 127615, 8.35 }
};
int i; // loop counter used to process each employee
// Loop through each employee to gather hours and calculate payroll
for (i = 0; i < SIZE; ++i)
{
// Prompt the user to enter hours worked for the employee
employeeData[i].hours = getHours(employeeData[i].clockNumber);
// Calculate overtime hours based on total hours worked
employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
// Calculate the employee's gross pay
employeeData[i].grossPay = calcGross(
employeeData[i].hours,
employeeData[i].wageRate,
employeeData[i].overtimeHrs
);
}
// Print report header before displaying employee data
printHeader();
// Loop through the structure array and print each employee record
for (i = 0; i < SIZE; ++i)
{
printEmp (employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
return(0); // indicate successful program completion
} // end main
//**************************************************************
//
// Function: getHours
//
// Purpose: Prompts the user to enter the number of hours worked
// for a specific employee and returns the value to the caller.
//
// Parameters:
// clockNumber - unique employee clock number
//
// Returns:
// float - hours worked by the employee
//
//**************************************************************
float getHours (long int clockNumber)
{
float hoursWorked; // local variable to store user input
// Ask the user to enter the hours worked for the employee
printf("\nEnter hours worked by emp # %06li: ", clockNumber
);
// Read the value entered by the user
scanf ("%f", &hoursWorked
);
// Return the hours worked to the calling function
return (hoursWorked);
} // end getHours
//**************************************************************
//
// Function: calcOvertime
//
// Purpose: Determines the number of overtime hours worked
// by an employee based on the standard work week.
//
// Parameters:
// hours - total hours worked in the week
//
// Returns:
// float - overtime hours worked
//
//**************************************************************
float calcOvertime(float hours)
{
float overtime; // local variable to store overtime hours
// Determine if employee worked more than standard hours
if (hours > STD_HOURS)
{
// Overtime is the number of hours beyond 40
overtime = hours - STD_HOURS;
}
else
{
// No overtime if hours are less than or equal to 40
overtime = 0.0;
}
// Return calculated overtime hours
return overtime;
} // end calcOvertime
//**************************************************************
//
// Function: calcGross
//
// Purpose: Calculates the total gross pay for an employee
// including regular pay and overtime pay.
//
// Parameters:
// hours - total hours worked
// wageRate - employee hourly wage
// overtimeHrs - number of overtime hours worked
//
// Returns:
// float - total gross pay
//
//**************************************************************
float calcGross(float hours, float wageRate, float overtimeHrs)
{
float regularPay; // pay earned from regular hours
float overtimePay; // pay earned from overtime hours
float gross; // total gross pay
// Calculate pay for regular hours (hours minus overtime)
regularPay = (hours - overtimeHrs) * wageRate;
// Calculate overtime pay using overtime multiplier
overtimePay = overtimeHrs * wageRate * OT_RATE;
// Total gross pay is the sum of regular and overtime pay
gross = regularPay + overtimePay;
// Return total gross pay
return gross;
} // end calcGross
//**************************************************************
//
// Function: printHeader
//
// Purpose: Prints the payroll report header and column labels.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader (void)
{
// Print report title
printf ("\n\n*** Pay Calculator ***\n");
// Print column headings for the payroll table
printf("\nClock# Wage Hours OT Gross\n");
// Print a separator line for readability
printf("------------------------------------------------\n");
} // end printHeader
//*************************************************************
//
// Function: printEmp
//
// Purpose: Displays payroll information for a single employee
// in formatted column output.
//
// Parameters:
// clockNumber - employee identification number
// wageRate - hourly wage rate
// hours - total hours worked
// overtimeHrs - overtime hours worked
// grossPay - calculated gross pay
//
// Returns: void
//
//**************************************************************
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
// Print employee payroll information in a formatted row
printf("\n %06li %5.2f %4.1f %4.1f %8.2f", clockNumber, wageRate, hours,
overtimeHrs, grossPay);
} // end printEmp