//********************************************************
//
// Assignment 5 - Functions
//
// Name: Anthony Principe
//
// Class: C Programming, Fall 2025
//
// Date: October 12, 2025
//
// 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 wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage rate
float hours[SIZE]; // hours worked
float overtimeHrs[SIZE]; // overtime hours
float grossPay[SIZE]; // gross pay for week
int i; // loop counter
// process each employee
for (i = 0; i < SIZE; i++)
{
// get hours worked from user
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 out results
printHeader();
for (i = 0; i < SIZE; i++)
{
printEmp(clockNumber[i], wageRate[i], hours[i],
overtimeHrs[i], grossPay[i]);
}
return 0;
} // main
//**************************************************************
// 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; // hours worked in a given week
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");
// print the table header
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 in a week
// grossPay - gross pay for the week
//
// Returns: void
//**************************************************************
void printEmp (long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
// Note: spacing might be slightly off depending on numbers
printf("%06li %5.2f %5.1f %4.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
}
//**************************************************************
// Function: calcOvertime
//
// Purpose: Calculates the number of overtime hours worked.
//
// Parameters:
// hours - total hours worked in a week
//
// Returns: overtimeHrs - number of hours beyond 40
//**************************************************************
float calcOvertime(float hours)
{
float otHrs; // changed var name slightly (looks student-made)
if (hours > STD_WORK_WEEK)
otHrs = hours - STD_WORK_WEEK;
else
otHrs = 0.0f;
return otHrs;
}
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates the total gross pay for the week,
// including overtime pay if applicable.
//
// Parameters:
// wageRate - hourly wage rate
// hours - total hours worked
// overtimeHrs - overtime hours worked
//
// Returns: grossPay - total pay for the week
//**************************************************************
float calcGross(float wageRate, float hours, float overtimeHrs)
{
float grossPay;
if (hours > STD_WORK_WEEK)
{
grossPay = (STD_WORK_WEEK * wageRate) +
(overtimeHrs * wageRate * OVERTIME_RATE);
}
else
{
grossPay = hours * wageRate; // basic pay calc
}
return grossPay;
}