#include <stdio.h>
// ------------------------------------------------------------
// Program Constants
// ------------------------------------------------------------
#define SIZE 5 // number of employees to process
#define STD_HOURS 40.0 // standard weekly hours before overtime applies
#define OT_RATE 1.5 // overtime pay multiplier (time and a half)
int main()
{
// ------------------------------------------------------------
// Variable Declarations
// ------------------------------------------------------------
// Unique employee ID numbers
long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
// Hourly wage rate for each employee
float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
// Arrays to store weekly payroll data
float hours[SIZE]; // hours worked in the week
float overtimeHrs[SIZE]; // overtime hours worked
float normalPay[SIZE]; // pay for up to 40 hours
float overtimePay[SIZE]; // pay for overtime hours
float grossPay[SIZE]; // total weekly pay (normal + overtime)
int i; // loop index
// Totals for summary calculations
float totalWage = 0.0; // total of all wage rates
float totalHours = 0.0; // total hours worked
float totalOTHours = 0.0; // total overtime hours
float totalNormal = 0.0; // total normal pay
float totalOTPay = 0.0; // total overtime pay
float totalGross = 0.0; // total gross pay
// ------------------------------------------------------------
// Program Header
// ------------------------------------------------------------
printf("\n*** Pay Calculator ***\n\n");
// ------------------------------------------------------------
// Input Loop — Read Hours Worked for Each Employee
// ------------------------------------------------------------
for (i = 0; i < SIZE; i++)
{
// Prompt user for hours worked for the current employee
printf("\nEnter the number of hours worked for employee %ld: ", clockNumber[i]);
// --------------------------------------------------------
// Payroll Calculations for Each Employee
// --------------------------------------------------------
// Check if employee worked overtime
if (hours[i] >= STD_HOURS)
{
// Calculate overtime hours
overtimeHrs[i] = hours[i] - STD_HOURS;
// Normal pay is capped at 40 hours
normalPay[i] = STD_HOURS * wageRate[i];
// Overtime pay uses the OT multiplier
overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
}
else
{
// No overtime worked
overtimeHrs[i] = 0.0;
// All hours are normal hours
normalPay[i] = hours[i] * wageRate[i];
// No overtime pay
overtimePay[i] = 0.0;
}
// Gross pay is the sum of normal and overtime pay
grossPay[i] = normalPay[i] + overtimePay[i];
}
// ------------------------------------------------------------
// Output Table Header
// ------------------------------------------------------------
printf("\nClock# Wage Hours OT Normal OT Pay Gross\n"); printf("-----------------------------------------------------------\n");
// ------------------------------------------------------------
// Output Loop — Print Payroll Data for Each Employee
// ------------------------------------------------------------
for (i = 0; i < SIZE; i++)
{
// Print one row of payroll information
printf("%06ld %5.2f %5.1f %4.1f %7.2f %7.2f %7.2f\n", clockNumber[i],
wageRate[i],
hours[i],
overtimeHrs[i],
normalPay[i],
overtimePay[i],
grossPay[i]);
// --------------------------------------------------------
// Accumulate Totals for Summary Section
// --------------------------------------------------------
totalWage += wageRate[i];
totalHours += hours[i];
totalOTHours += overtimeHrs[i];
totalNormal += normalPay[i];
totalOTPay += overtimePay[i];
totalGross += grossPay[i];
}
// Divider line before totals
printf("-----------------------------------------------------------\n");
// ------------------------------------------------------------
// Totals Row — Aligned with Table Columns
// ------------------------------------------------------------
printf("TOTALS %5.2f %5.1f %4.1f %7.2f %7.2f %7.2f\n", totalWage, // total wage rates
totalHours, // total hours worked
totalOTHours, // total overtime hours
totalNormal, // total normal pay
totalOTPay, // total overtime pay
totalGross); // total gross pay
// ------------------------------------------------------------
// Averages Row — Aligned with Table Columns
// ------------------------------------------------------------
printf("AVERAGES %5.2f %5.1f %4.1f %7.2f %7.2f %7.2f\n", totalWage / SIZE, // average wage rate
totalHours / SIZE, // average hours worked
totalOTHours / SIZE, // average overtime hours
totalNormal / SIZE, // average normal pay
totalOTPay / SIZE, // average overtime pay
totalGross / SIZE); // average gross pay
// End of program
return 0;
}