//********************************************************
//
// Assignment 7 - Structures and Strings
//
// Name: John Semenuk
//
// Class: C Programming, Spring 2026
//
// Date: 29-Mar-2026
//
// Description: Program calculates overtime, gross pay, state & federal tax,
// net pay, and prints totals, averages, min/max values.
// Uses structures for employee info, totals, and min/max statistics.
//
//********************************************************
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//*******************************************************
// Constants
//*******************************************************
#define SIZE 5 // Number of employees to process
#define STD_HOURS 40.0 // Standard hours before overtime
#define OT_RATE 1.5 // Overtime multiplier
#define MA_TAX_RATE 0.05 // State tax rates
#define NH_TAX_RATE 0.0
#define VT_TAX_RATE 0.06
#define CA_TAX_RATE 0.07
#define DEFAULT_TAX_RATE 0.08
#define FED_TAX_RATE 0.25
#define NAME_SIZE 20
#define TAX_STATE_SIZE 3
#define FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
//*******************************************************
// Structures
//*******************************************************
// Stores first and last names for an employee
struct name {
char firstName[FIRST_NAME_SIZE];
char lastName[LAST_NAME_SIZE];
};
// Employee structure containing name, clock number, hours, pay, taxes
struct employee {
struct name empName; // Employee's first and last name
char taxState[TAX_STATE_SIZE]; // Employee's tax state
long int clockNumber; // Unique employee ID
float wageRate; // Hourly wage
float hours; // Hours worked
float overtimeHrs; // Calculated overtime hours
float grossPay; // Gross pay including overtime
float stateTax; // State tax amount
float fedTax; // Federal tax amount
float netPay; // Net pay after taxes
};
// Totals structure to track cumulative sums for all employees
struct totals {
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
// Min/Max structure to track min/max values for all employees
struct min_max {
float min_wageRate;
float min_hours;
float min_overtimeHrs;
float min_grossPay;
float min_stateTax;
float min_fedTax;
float min_netPay;
float max_wageRate;
float max_hours;
float max_overtimeHrs;
float max_grossPay;
float max_stateTax;
float max_fedTax;
float max_netPay;
};
//*******************************************************
// Function Prototypes
//*******************************************************
float getHours(long int clockNumber); // Prompt user for hours worked
float calcOvertimeHrs(float hours); // Calculate overtime hours
float calcGrossPay(float wageRate, float hours, float overtimeHrs); // Calculate gross pay
void printHeader(void); // Print formatted table header
void printEmp(char firstName[], char lastName[], char taxState[], long int clockNumber,
float wageRate, float hours, float overtimeHrs, float grossPay,
float stateTax, float fedTax, float netPay); // Print employee info
float calcStateTax(float grossPay, char taxState[]); // Determine state tax
float calcFedTax(float grossPay); // Determine federal tax
float calcNetPay(float grossPay, float stateTax, float fedTax); // Calculate net pay
struct totals calcEmployeeTotals(float wageRate, float hours, float overtimeHrs,
float grossPay, float stateTax, float fedTax,
float netPay, struct totals employeeTotals); // Update totals
struct min_max calcEmployeeMinMax(float wageRate, float hours, float overtimeHrs,
float grossPay, float stateTax, float fedTax,
float netPay, struct min_max employeeMinMax,
int arrayIndex); // Update min/max values
void printEmpStatistics(struct totals employeeTotals, struct min_max employeeMinMax, int theSize); // Print totals, averages, min/max
//*******************************************************
// Main Function
//*******************************************************
int main() {
int i;
// Hardcoded employee data (first/last name, tax state, clock number, wage)
struct employee employeeData[SIZE] = {
{ {"Connie", "Cobol"}, "MA", 98401, 10.60 },
{ {"Mary", "Apl"}, "NH", 526488, 9.75 },
{ {"Frank", "Fortran"}, "VT", 765349, 10.50 },
{ {"Jeff", "Ada"}, "NY", 34645, 12.25 },
{ {"Anton", "Pascal"}, "CA", 127615, 8.35 }
};
struct totals employeeTotals = {0}; // Initialize totals
struct min_max employeeMinMax = {0}; // Initialize min/max
//*******************************************************
// Process each employee
//*******************************************************
for (i = 0; i < SIZE; ++i) {
// Get hours worked
employeeData[i].hours = getHours(employeeData[i].clockNumber);
// Calculate overtime hours
employeeData[i].overtimeHrs = calcOvertimeHrs(employeeData[i].hours);
// Calculate gross pay
employeeData[i].grossPay = calcGrossPay(employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs);
// Calculate taxes
employeeData[i].stateTax = calcStateTax(employeeData[i].grossPay,
employeeData[i].taxState);
employeeData[i].fedTax = calcFedTax(employeeData[i].grossPay);
// Calculate net pay
employeeData[i].netPay = calcNetPay(employeeData[i].grossPay,
employeeData[i].stateTax,
employeeData[i].fedTax);
// Update totals
employeeTotals = calcEmployeeTotals(employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay,
employeeData[i].stateTax,
employeeData[i].fedTax,
employeeData[i].netPay,
employeeTotals);
// Update min/max values
employeeMinMax = calcEmployeeMinMax(employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay,
employeeData[i].stateTax,
employeeData[i].fedTax,
employeeData[i].netPay,
employeeMinMax, i);
}
//*******************************************************
// Print results
//*******************************************************
printHeader();
for (i = 0; i < SIZE; ++i) {
printEmp(employeeData[i].empName.firstName,
employeeData[i].empName.lastName,
employeeData[i].taxState,
employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay,
employeeData[i].stateTax,
employeeData[i].fedTax,
employeeData[i].netPay);
}
// Print totals, averages, min/max
printEmpStatistics(employeeTotals, employeeMinMax, SIZE);
return 0;
}
//**************************************************************
// Function Definitions
//**************************************************************
// Prompt user to enter hours worked
float getHours(long int clockNumber) {
float theHoursWorked;
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &theHoursWorked
); return theHoursWorked;
}
// Print table header
void printHeader(void) {
printf("\n\n*** Pay Calculator ***\n"); printf("\n--------------------------------------------------------------"); printf("-------------------"); printf("\nName Tax Clock# Wage Hours OT Gross "); printf("\n--------------------------------------------------------------"); printf("-------------------"); }
// Print individual employee info in formatted table
void printEmp(char firstName[], char lastName[], char taxState[], long int clockNumber,
float wageRate, float hours, float overtimeHrs, float grossPay,
float stateTax, float fedTax, float netPay) {
char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f", name, taxState, clockNumber, wageRate, hours, overtimeHrs, grossPay, stateTax, fedTax, netPay);
}
// Calculate overtime hours
float calcOvertimeHrs(float hours) {
return (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
}
// Calculate gross pay including overtime
float calcGrossPay(float wageRate, float hours, float overtimeHrs) {
float normalPay = wageRate * (hours - overtimeHrs);
float overtimePay = overtimeHrs * (OT_RATE * wageRate);
return normalPay + overtimePay;
}
// Calculate state tax based on employee's tax state
float calcStateTax(float grossPay, char taxState[]) {
float tax;
taxState
[0] = toupper(taxState
[0]); taxState
[1] = toupper(taxState
[1]); if (strcmp(taxState
, "MA") == 0) tax
= grossPay
* MA_TAX_RATE
; else if (strcmp(taxState
, "NH") == 0) tax
= grossPay
* NH_TAX_RATE
; else if (strcmp(taxState
, "VT") == 0) tax
= grossPay
* VT_TAX_RATE
; else if (strcmp(taxState
, "CA") == 0) tax
= grossPay
* CA_TAX_RATE
; else tax = grossPay * DEFAULT_TAX_RATE;
return tax;
}
// Calculate federal tax
float calcFedTax(float grossPay) {
return grossPay * FED_TAX_RATE;
}
// Calculate net pay after all taxes
float calcNetPay(float grossPay, float stateTax, float fedTax) {
return grossPay - (stateTax + fedTax);
}
// Update totals for all employees
struct totals calcEmployeeTotals(float wageRate, float hours, float overtimeHrs,
float grossPay, float stateTax, float fedTax,
float netPay, struct totals employeeTotals) {
employeeTotals.total_wageRate += wageRate;
employeeTotals.total_hours += hours;
employeeTotals.total_overtimeHrs += overtimeHrs;
employeeTotals.total_grossPay += grossPay;
employeeTotals.total_stateTax += stateTax;
employeeTotals.total_fedTax += fedTax;
employeeTotals.total_netPay += netPay;
return employeeTotals;
}
// Update min/max values for all employees
struct min_max calcEmployeeMinMax(float wageRate, float hours, float overtimeHrs,
float grossPay, float stateTax, float fedTax,
float netPay, struct min_max employeeMinMax,
int arrayIndex) {
if (arrayIndex == 0) { // First employee initializes min/max
employeeMinMax.min_wageRate = employeeMinMax.max_wageRate = wageRate;
employeeMinMax.min_hours = employeeMinMax.max_hours = hours;
employeeMinMax.min_overtimeHrs = employeeMinMax.max_overtimeHrs = overtimeHrs;
employeeMinMax.min_grossPay = employeeMinMax.max_grossPay = grossPay;
employeeMinMax.min_stateTax = employeeMinMax.max_stateTax = stateTax;
employeeMinMax.min_fedTax = employeeMinMax.max_fedTax = fedTax;
employeeMinMax.min_netPay = employeeMinMax.max_netPay = netPay;
} else { // Compare and update min/max
if (wageRate < employeeMinMax.min_wageRate) employeeMinMax.min_wageRate = wageRate;
if (wageRate > employeeMinMax.max_wageRate) employeeMinMax.max_wageRate = wageRate;
if (hours < employeeMinMax.min_hours) employeeMinMax.min_hours = hours;
if (hours > employeeMinMax.max_hours) employeeMinMax.max_hours = hours;
if (overtimeHrs < employeeMinMax.min_overtimeHrs) employeeMinMax.min_overtimeHrs = overtimeHrs;
if (overtimeHrs > employeeMinMax.max_overtimeHrs) employeeMinMax.max_overtimeHrs = overtimeHrs;
if (grossPay < employeeMinMax.min_grossPay) employeeMinMax.min_grossPay = grossPay;
if (grossPay > employeeMinMax.max_grossPay) employeeMinMax.max_grossPay = grossPay;
if (stateTax < employeeMinMax.min_stateTax) employeeMinMax.min_stateTax = stateTax;
if (stateTax > employeeMinMax.max_stateTax) employeeMinMax.max_stateTax = stateTax;
if (fedTax < employeeMinMax.min_fedTax) employeeMinMax.min_fedTax = fedTax;
if (fedTax > employeeMinMax.max_fedTax) employeeMinMax.max_fedTax = fedTax;
if (netPay < employeeMinMax.min_netPay) employeeMinMax.min_netPay = netPay;
if (netPay > employeeMinMax.max_netPay) employeeMinMax.max_netPay = netPay;
}
return employeeMinMax;
}
// Print totals, averages, min/max statistics
void printEmpStatistics(struct totals employeeTotals, struct min_max employeeMinMax, int theSize) {
printf("\n--------------------------------------------------------------"); printf("-------------------"); printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeTotals.total_wageRate, employeeTotals.total_hours, employeeTotals.total_overtimeHrs,
employeeTotals.total_grossPay, employeeTotals.total_stateTax, employeeTotals.total_fedTax,
employeeTotals.total_netPay);
if (theSize > 0)
printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeTotals.total_wageRate/theSize, employeeTotals.total_hours/theSize,
employeeTotals.total_overtimeHrs/theSize, employeeTotals.total_grossPay/theSize,
employeeTotals.total_stateTax/theSize, employeeTotals.total_fedTax/theSize,
employeeTotals.total_netPay/theSize);
printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeMinMax.min_wageRate, employeeMinMax.min_hours, employeeMinMax.min_overtimeHrs,
employeeMinMax.min_grossPay, employeeMinMax.min_stateTax, employeeMinMax.min_fedTax,
employeeMinMax.min_netPay);
printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f", employeeMinMax.max_wageRate, employeeMinMax.max_hours, employeeMinMax.max_overtimeHrs,
employeeMinMax.max_grossPay, employeeMinMax.max_stateTax, employeeMinMax.max_fedTax,
employeeMinMax.max_netPay);
}