//********************************************************
//
// Assignment 6 - Structures
//
// Name: John Semenuk
//
// Class: C Programming, Spring 2026
//
// Date: 8-Mar-2026
//
// Description:
// Program which determines overtime hours and gross pay
// for a set of employees. Employee data is stored using
// an array of structures. The program prompts the user
// for hours worked and calculates overtime and gross pay.
//
//********************************************************
#include <stdio.h>
// Program Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
// Structure Definition
struct employee
{
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
// Function Prototypes
float getHours(long int clockNumber);
float calcOvertime(float hours);
float calcGross(float wageRate, float hours, float overtimeHrs);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
int main()
{
struct employee employeeData[SIZE] =
{
{98401, 10.60},
{526488, 9.75},
{765349, 10.50},
{34645, 12.25},
{127615, 8.35}
};
int i;
// Input and calculations
for (i = 0; i < SIZE; i++)
{
employeeData[i].hours =
getHours(employeeData[i].clockNumber);
employeeData[i].overtimeHrs =
calcOvertime(employeeData[i].hours);
employeeData[i].grossPay =
calcGross(employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs);
}
printHeader();
for (i = 0; i < SIZE; i++)
{
printEmp(employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
return 0;
}
//**************************************************************
// Function: getHours
//
// Purpose:
// Prompts the user to enter the number of hours worked
// by an employee and returns that value.
//
// Parameters:
// clockNumber - unique employee identification number
//
// Returns:
// float - number of hours worked by the employee
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked;
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
);
return hoursWorked;
}
//**************************************************************
// Function: calcOvertime
//
// Purpose:
// Determines how many overtime hours an employee worked.
// Overtime is any time greater than the standard work week.
//
// Parameters:
// hours - total hours worked by employee
//
// Returns:
// float - overtime hours worked
//**************************************************************
float calcOvertime(float hours)
{
float overtime;
if (hours > STD_HOURS)
overtime = hours - STD_HOURS;
else
overtime = 0.0;
return overtime;
}
//**************************************************************
// Function: calcGross
//
// Purpose:
// Calculates the gross pay for an employee using the
// employee wage rate, total hours worked, and overtime.
//
// Parameters:
// wageRate - employee hourly wage
// hours - total hours worked
// overtimeHrs - overtime hours worked
//
// Returns:
// float - total gross pay for the week
//**************************************************************
float calcGross(float wageRate, float hours, float overtimeHrs)
{
float normalPay;
float overtimePay;
float grossPay;
if (hours > STD_HOURS)
normalPay = STD_HOURS * wageRate;
else
normalPay = hours * wageRate;
overtimePay = overtimeHrs * wageRate * OT_RATE;
grossPay = normalPay + overtimePay;
return grossPay;
}
//**************************************************************
// Function: printHeader
//
// Purpose:
// Prints the column headings for the employee pay table.
//
// Parameters:
// none
//
// Returns:
// void
//**************************************************************
void printHeader(void)
{
printf("\n\n----------------------------------------------------------"); printf("\n Clock# Wage Hours OT Gross"); printf("\n----------------------------------------------------------");
}
//**************************************************************
// Function: printEmp
//
// Purpose:
// Displays a single employee's payroll information.
//
// Parameters:
// clockNumber - employee ID
// wageRate - hourly wage
// hours - total hours worked
// overtimeHrs - overtime hours worked
// grossPay - total weekly gross pay
//
// Returns:
// void
//**************************************************************
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
printf("\n %06li %5.2f %4.1f %4.1f %8.2f", clockNumber, wageRate, hours,
overtimeHrs, grossPay);
}