//********************************************************
//
// Assignment 5 - Functions
//
// Name: David Morse
//
// Class: C Programming, Spring 2026
//
// Date: 2/26/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);
void printHeader (void);
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
float calcOvertime (float hours);
float calcGross (float wageRate, float hours, float overtimeHrs);
int main()
{
/* Variable Declarations */
long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; // ID
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}; // hourly wage rate
// process each employee
for (i = 0; i < SIZE; ++i)
{
// Read in hours for employee
hours[i] = getHours (clockNumber[i]);
// Calculate overtime hours
overtimeHrs[i] = calcOvertime(hours[i]);
// Calculate gross pay
grossPay[i] = calcGross(wageRate[i], hours[i], overtimeHrs[i]);
}
// print the header info
printHeader();
// print out each employee
for (i = 0; i < SIZE; ++i)
{
printEmp (clockNumber[i], wageRate[i], hours[i],
overtimeHrs[i], grossPay[i]);
}
return (0);
} // end main
//**************************************************************
// Function: getHours
//**************************************************************
float getHours (long int clockNumber)
{
float hoursWorked; // hours worked in a given week
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf ("%f", &hoursWorked
);
return (hoursWorked);
} // end getHours
//**************************************************************
// Function: calcOvertime
//
// Purpose: Calculates overtime hours worked.
//
// Parameters:
// hours - total hours worked in week
//
// Returns:
// overtime hours
//**************************************************************
float calcOvertime (float hours)
{
float overtime; // overtime hours
if (hours > STD_WORK_WEEK)
overtime = hours - STD_WORK_WEEK;
else
overtime = 0.0f;
return overtime;
}
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates gross pay including overtime.
//
// Parameters:
// wageRate - hourly wage rate
// hours - hours worked
// overtimeHrs - overtime hours
//
// Returns:
// gross pay
//**************************************************************
float calcGross (float wageRate, float hours, float overtimeHrs)
{
float regularPay; // regular pay
float overtimePay; // overtime pay
float gross; // total gross pay
regularPay = wageRate * (hours - overtimeHrs);
overtimePay = wageRate * OVERTIME_RATE * overtimeHrs;
gross = regularPay + overtimePay;
return gross;
}
//**************************************************************
// Function: printHeader
//**************************************************************
void printHeader (void)
{
printf ("\n\n*** Pay Calculator ***\n"); printf("\nClock# Wage Hours OT Gross\n"); printf("------------------------------------------------\n"); }
//**************************************************************
// Function: printEmp
//
// Purpose: Prints employee payroll information in table format.
//
//**************************************************************
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
printf("%06li %5.2f %5.1f %5.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
}