//********************************************************
//
// Assignment 6 - Structures
//
// Name: Carlos Dominguez
//
// Class: C Programming, Spring 2026
//
// Date: March 8th, 2026 -----------almost spring!
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// Call by Value design
//
//********************************************************
// Define and Includes
#include <stdio.h>
// Define Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
// Define a global structure type to pass employee data between functions
struct employee
{
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
// Function Prototypes
float getHours(long int clockNumber);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
// Added function prototypes
float calcOvertime(float hours);
float calcGross(float hours, float wageRate, float overtimeHrs);
int main()
{
// Local array of employee structures
struct employee employeeData[SIZE] = {
{ 98401, 10.60 },
{ 526488, 9.75 },
{ 765349, 10.50 },
{ 34645, 12.25 },
{ 127615, 8.35 }
};
int i; // loop index
// Loop through each employee and gather/calculate data
for (i = 0; i < SIZE; ++i)
{
// Get hours worked for this employee
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 table header
printHeader();
// Print each employee's data
for (i = 0; i < SIZE; ++i)
{
printEmp(employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
return 0; // success
}
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result in a local variable
// that is passed back to the calling function.
//
// Parameters:
// clockNumber - The unique employee ID
//
// Returns:
// hoursWorked - hours worked in a given week
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked;
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
);
return hoursWorked;
}
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// 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 out all the information for an employee
// in a nice and orderly table format.
//
// Parameters:
// clockNumber - unique employee ID
// wageRate - hourly wage rate
// hours - hours worked for the week
// overtimeHrs - overtime hours worked
// grossPay - gross pay for the week
//
// 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);
}
//**************************************************************
// Function: calcOvertime
//
// Purpose: Calculates overtime hours based on STD_HOURS.
//
// Parameters:
// hours - total hours worked
//
// Returns:
// overtime hours (0 if none)
//**************************************************************
float calcOvertime(float hours)
{
if (hours > STD_HOURS)
return hours - STD_HOURS;
else
return 0.0;
}
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates gross pay including overtime.
//
// Parameters:
// hours - total hours worked
// wageRate - hourly wage
// overtimeHrs - overtime hours already calculated
//
// Returns:
// gross pay for the week
//**************************************************************
float calcGross(float hours, float wageRate, float overtimeHrs)
{
float normalPay;
float overtimePay;
if (overtimeHrs > 0)
{
normalPay = STD_HOURS * wageRate;
overtimePay = overtimeHrs * wageRate * OT_RATE;
}
else
{
normalPay = hours * wageRate;
overtimePay = 0.0;
}
return normalPay + overtimePay;
}