//********************************************************
//
// Assignment 5 - Functions
//
// Name: <Mario Morkus>
//
// Class: C Programming, <Spring 2026>
//
// Date: <03/01/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 calcOvertimeHrs (float hours);
float calcGrossPay (float hours, float wageRate, 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];
float hours[SIZE];
int i;
float overtimeHrs[SIZE];
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] = calcOvertimeHrs(hours[i]);
// Calculate gross pay
grossPay[i] = calcGrossPay(hours[i], wageRate[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);
} // 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;
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
);
return (hoursWorked);
} // getHours
//**************************************************************
// Function: calcOvertimeHrs
//
// Purpose: Calculates the number of overtime hours worked by
// an employee in a given week. If hours worked is at or below
// the standard work week, overtime is zero.
//
// Parameters: hours - total hours worked in a given week
//
// Returns: overtimeHrs - the number of overtime hours worked
//
//**************************************************************
float calcOvertimeHrs(float hours)
{
float overtimeHrs;
// Overtime is any hours above the standard work week
if (hours > STD_WORK_WEEK)
overtimeHrs = hours - STD_WORK_WEEK;
else
overtimeHrs = 0;
return (overtimeHrs);
} // calcOvertimeHrs
//**************************************************************
// Function: calcGrossPay
//
// Purpose: Calculates the gross pay for an employee based on
// their hours worked, wage rate, and overtime hours. Overtime
// is paid at 1.5 times the normal wage rate.
//
// Parameters:
//
// hours - total hours worked in a given week
// wageRate - hourly wage rate
// overtimeHrs - overtime hours worked in a given week
//
// Returns: grossPay - the total gross pay for the week
//
//**************************************************************
float calcGrossPay(float hours, float wageRate, float overtimeHrs)
{
float grossPay;
// Gross pay = standard pay + overtime pay (if any)
if (overtimeHrs > 0)
grossPay = (STD_WORK_WEEK * wageRate)
+ (overtimeHrs * wageRate * OVERTIME_RATE);
else
grossPay = hours * wageRate;
return (grossPay);
} // calcGrossPay
//**************************************************************
// 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");
} // printHeader
//**************************************************************
// 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)
{
printf("%06li %5.2f %5.1f %5.1f %8.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
} // printEmp