//********************************************************
//
// Assignment 5 - Functions
//
// Name: Jalen Tam
//
// Class: C Programming, Fall 2025
//
// Date: October 10, 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 STD_HOURS 40
#define OVT_RATE 1.5
// Function prototypes
float getHours (int clockNumber);
float overtimeHours (float hoursWorked);
float getRegularPay (float hours, float wage);
float getOvertimePay (float hours, float wage);
// FUNCTION getHours
// Prompt for hours worked
// Parameters: clockNumber - Employee clock number
// Returns: Hours worked
float getHours (int clockNumber) {
//Initialize hours worked
float hoursWorked;
//Prompts hour worked and scans it into hoursWorked variable
//printf ("Enter hours worked for %06i ", clockNumber);
scanf ("%f", &hoursWorked
);
return hoursWorked;
}
// FUNCTION getOvertimeHours
// Calculates overtime hours worked
// Parameters: hoursWorked - hours worked
// Returns: overtime hours
float getOvertimeHours (float hoursWorked) {
//Initialize overtime hours worked variable
float ovtHours;
//calculating overtime hours
//If hours worked is more than 40
if (hoursWorked > STD_HOURS){
ovtHours = hoursWorked - STD_HOURS;
}
//Hours worked is less than 40 hours
else {
ovtHours = 0;
}
return ovtHours;
}
// FUNCTION getRegularPay
// Calculates pay for regular hours worked
// Parameters: hours - total hours worked, wage - wage rate per regular hour worked
// Returns: regular pay
float getRegularPay (float hours, float wage) {
//Initialize regular pay variable
float regPay;
if (hours > STD_HOURS) { //Calculates pay if overtime is worked
regPay = STD_HOURS * wage;
}
else { //Calculates pay if no overtime
regPay = hours * wage;
}
//returns pay for regular wage rate
return regPay;
}
// FUNCTION getOvertimePay
// Calculates pay for overtime hours worked
// Parameters: hours - overtime hours worked, wage - wage rate per regular hour worked
// Returns: overtime pay
float getOvertimePay (float hours, float wage) {
float ovtPay;
ovtPay = hours * (wage * OVT_RATE);
return ovtPay;
}
// FUNCTION getGrossPay
// Calculates gross pay for regular and overtime hours worked
// Parameters: ovtPay - overtime pay, regPay - regular pay
// Returns: gross pay
float getGrossPay (float ovtPay, float regPay) {
float gross;
gross = ovtPay + regPay;
return gross;
}
int main() {
int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615}; //Clock number array
float wageRate [SIZE] = {10.60, 9.75, 10.50, 12.25, 8.35}; //Wage rate array
float hoursWorked [SIZE] = {}; //Initialize hours worked array
float overtimeHours [SIZE] = {}; //Initialize overtime hours array
float regularPay [SIZE] = {}; //Initialize regular pay array
float overtimePay [SIZE] = {}; //Initialize overtime pay array
float grossPay [SIZE] = {}; //Initialize gross pay array
printf("Clock# Wage Hours OT Reg Pay OT Pay Gross\n"); printf("---------------------------------------------------------\n");
int i;
for (i = 0; i < SIZE; ++i){
hoursWorked[i] = getHours(clockNumber[i]);
overtimeHours[i] = getOvertimeHours(hoursWorked[i]);
regularPay[i] = getRegularPay(hoursWorked[i], wageRate[i]);
overtimePay[i] = getOvertimePay(overtimeHours[i], wageRate[i]);
grossPay[i] = getGrossPay(overtimePay[i], regularPay[i]);
printf("%06i\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\t %.2f\n", clockNumber
[i
], wageRate
[i
], hoursWorked
[i
], overtimeHours
[i
], regularPay
[i
], overtimePay
[i
], grossPay
[i
]);
}
return 0;
}