//********************************************************
//
// Assignment 5 - Functions
//
// Name: Robert Hyde
//
// Class: C Programming, Fall 2026
//
// Date: October 5, 2026
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// All functions are called by value
//
//********************************************************
#include <stdio.h>
// constants
#define SIZE 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f
// function prototypes
float getHours (long int clockNumber);
float calculateOvertime (float hours);
float calculateGrossPay (float wageRate, float hours, float overtimeHrs);
void printHeader (void);
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
int main()
{
/* Variable Declarations */
long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
float grossPay[SIZE]; // gross pay
float hours[SIZE]; // hours worked in a given week
int i; // loop and array index
float overtimeHrs[SIZE]; // overtime hours
float wageRate[SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35};
// process each employee
for (i = 0; i < SIZE; ++i)
{
// Read in hours for employee
hours[i] = getHours(clockNumber[i]);
// Calculate overtime hours
overtimeHrs[i] = calculateOvertime(hours[i]);
// Calculate gross pay
grossPay[i] = calculateGrossPay(wageRate[i], hours[i],
overtimeHrs[i]);
} // for
// print the header info
printHeader();
// print out each employee
for (i = 0; i < SIZE; ++i)
{
// Print all the employees - call by value
printEmp(clockNumber[i], wageRate[i], hours[i],
overtimeHrs[i], grossPay[i]);
} // for
return (0);
} // main
//**************************************************************
// Function: getHours
//
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked; // hours worked in a given week
// Read in hours for employee
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
);
// return hours back to the calling function
return (hoursWorked);
} // getHours
//**************************************************************
// Function: calculateOvertime
//
//**************************************************************
float calculateOvertime(float hours)
{
float overtimeHrs;
if (hours > STD_WORK_WEEK)
{
overtimeHrs = hours - STD_WORK_WEEK;
}
else
{
overtimeHrs = 0.0f;
}
return (overtimeHrs);
} // calculateOvertime
//**************************************************************
// Function: calculateGrossPay
//
//**************************************************************
float calculateGrossPay(float wageRate, float hours, float overtimeHrs)
{
float regularHours;
float grossPay;
if (hours > STD_WORK_WEEK)
{
regularHours = STD_WORK_WEEK;
}
else
{
regularHours = hours;
}
grossPay = (regularHours * wageRate) +
(overtimeHrs * wageRate * OVERTIME_RATE);
return (grossPay);
} // calculateGrossPay
//**************************************************************
// Function: printHeader
//
//**************************************************************
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n");
// print the table header
printf("\n Clock# Wage Hours OT Gross\n"); printf(" ------------------------------------------\n");
} // printHeader
//**************************************************************
// Function: printEmp
//
//**************************************************************
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
// Print employee information in the required format
printf(" %06li %6.2f %5.1f %6.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
} // printEmp