//********************************************************
//
// Assignment 5 - Functions
//
// Name: <Amir Gharouadi>
//
// 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 calcOvertime(float hoursWorked);
float calcGross(float wageRate, float hoursWorked, float overtimeHrs);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
int main(void)
{
/* Variable Declarations */
long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; // ID
float wageRate[SIZE] = {10.60f, 9.75f, 10.50f, 12.25f, 8.35f}; // wage
float hours[SIZE]; // hours worked in a given week
float overtimeHrs[SIZE]; // overtime hours
float grossPay[SIZE]; // gross pay
int i; // loop and array index
// 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;
} // main
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and returns it 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;
} // getHours
//**************************************************************
// Function: calcOvertime
//
// Purpose: Calculates overtime hours based on hours worked.
// Overtime is any hours worked beyond STD_WORK_WEEK.
//
// Parameters: hoursWorked - total hours worked in the week
//
// Returns: overtimeHrs - overtime hours worked in the week
//
//**************************************************************
float calcOvertime(float hoursWorked)
{
float overtimeHrs; // overtime hours worked in the week
if (hoursWorked > STD_WORK_WEEK)
overtimeHrs = hoursWorked - STD_WORK_WEEK;
else
overtimeHrs = 0.0f;
return overtimeHrs;
} // calcOvertime
//**************************************************************
// Function: calcGross
//
// Purpose: Calculates gross pay using normal pay plus overtime pay.
//
// Parameters:
// wageRate - hourly wage rate
// hoursWorked - total hours worked in the week
// overtimeHrs - overtime hours worked in the week
//
// Returns: grossPay - gross pay for the week
//
//**************************************************************
float calcGross(float wageRate, float hoursWorked, float overtimeHrs)
{
float normalPay; // pay for non-overtime hours
float overtimePay; // pay for overtime hours
float grossPay; // total gross pay
if (hoursWorked > STD_WORK_WEEK)
normalPay = wageRate * STD_WORK_WEEK;
else
normalPay = wageRate * hoursWorked;
overtimePay = (OVERTIME_RATE * wageRate) * overtimeHrs;
grossPay = normalPay + overtimePay;
return grossPay;
} // calcGross
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader(void)
{
printf("\n\n--------------------------------------------------------------------------\n"); printf(" Clock# 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 %6.2f %6.1f %6.1f %9.2f\n", clockNumber, wageRate, hours, overtimeHrs, grossPay);
} // printEmp