//**************************************************************
//
// Assignment 9 - Linked Lists
//
// Name: John Semenuk
//
// Class: C Programming, Spring 2026
//
// Date: 04/08/2026
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// This assignment also adds the employee name, their tax state,
// and calculates the state tax, federal tax, and net pay.
//**************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME 20
#define STD_HOURS 40
#define OT_RATE 1.5
#define FED_TAX_RATE 0.10
#define MA_TAX_RATE 0.05
#define NH_TAX_RATE 0.00
#define VT_TAX_RATE 0.06
#define CA_TAX_RATE 0.08
#define DEFAULT_TAX_RATE 0.05
//**************************************************************
// Structure definitions
//**************************************************************
struct name {
char firstName[MAX_NAME];
char lastName[MAX_NAME];
};
struct employee {
struct name empName;
char taxState[3];
long clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
float stateTax;
float fedTax;
float netPay;
struct employee *next;
};
struct totals {
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
struct min_max {
float min_wageRate, max_wageRate;
float min_hours, max_hours;
float min_overtimeHrs, max_overtimeHrs;
float min_grossPay, max_grossPay;
float min_stateTax, max_stateTax;
float min_fedTax, max_fedTax;
float min_netPay, max_netPay;
};
//**************************************************************
// Function prototypes
//**************************************************************
void getEmpData(struct employee *current_ptr);
void calcOvertimeHrs(struct employee *head_ptr);
void calcGrossPay(struct employee *head_ptr);
void calcStateTax(struct employee *head_ptr);
void calcFedTax(struct employee *head_ptr);
void calcNetPay(struct employee *head_ptr);
void calcEmployeeTotals(struct employee *head_ptr, struct totals *emp_totals_ptr);
void calcEmployeeMinMax(struct employee *head_ptr, struct min_max *emp_minMax_ptr);
void printEmpReport(struct employee *head_ptr);
void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_minMax_ptr);
int main() {
//**************************************************************
// Create linked list of employees
//**************************************************************
int numEmployees = 5;
struct employee *head = NULL, *current = NULL, *prev = NULL;
for (int i = 0; i < numEmployees; i++) {
current
= malloc(sizeof(struct employee
)); if (!current
) { printf("Memory allocation failed\n"); return 1; } current->next = NULL;
getEmpData(current);
if (!head) head = current;
if (prev) prev->next = current;
prev = current;
}
//**************************************************************
// Pointers to totals and min_max structures
//**************************************************************
struct totals employeeTotals = {0};
struct totals *emp_totals_ptr = &employeeTotals;
struct min_max employeeMinMax;
struct min_max *emp_minMax_ptr = &employeeMinMax;
//**************************************************************
// Perform calculations
//**************************************************************
calcOvertimeHrs(head);
calcGrossPay(head);
calcStateTax(head);
calcFedTax(head);
calcNetPay(head);
calcEmployeeTotals(head, emp_totals_ptr);
calcEmployeeMinMax(head, emp_minMax_ptr);
//**************************************************************
// Print report and statistics
//**************************************************************
printEmpReport(head);
printEmpStatistics(emp_totals_ptr, emp_minMax_ptr);
//**************************************************************
// Free allocated memory
//**************************************************************
current = head;
struct employee *next;
while (current) {
next = current->next;
current = next;
}
return 0;
}
//**************************************************************
// Get employee data
//**************************************************************
void getEmpData(struct employee *current_ptr) {
char answer[3];
(void) scanf("%s", current_ptr
->empName.
firstName);
(void) scanf("%s", current_ptr
->empName.
lastName);
printf("Enter tax state (MA/NH/VT/CA): "); (void) scanf("%s", current_ptr
->taxState
);
printf("Enter clock number: "); (void) scanf("%li", ¤t_ptr
->clockNumber
);
(void) scanf("%f", ¤t_ptr
->wageRate
);
printf("Enter hours worked: "); (void) scanf("%f", ¤t_ptr
->hours
);
}
//**************************************************************
// Calculations
//**************************************************************
void calcOvertimeHrs(struct employee *head_ptr) {
struct employee *current_ptr;
for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
current_ptr->overtimeHrs = 0.0;
if (current_ptr->hours > STD_HOURS)
current_ptr->overtimeHrs = current_ptr->hours - STD_HOURS;
}
}
void calcGrossPay(struct employee *head_ptr) {
struct employee *current_ptr;
for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
float regularHours = current_ptr->hours;
if (regularHours > STD_HOURS) regularHours = STD_HOURS;
current_ptr->grossPay = regularHours * current_ptr->wageRate
+ current_ptr->overtimeHrs * current_ptr->wageRate * OT_RATE;
}
}
void calcStateTax(struct employee *head_ptr) {
struct employee *current_ptr;
for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
if (strcmp(current_ptr
->taxState
,"MA")==0) current_ptr
->stateTax
= current_ptr
->grossPay
* MA_TAX_RATE
; else if (strcmp(current_ptr
->taxState
,"NH")==0) current_ptr
->stateTax
= current_ptr
->grossPay
* NH_TAX_RATE
; else if (strcmp(current_ptr
->taxState
,"VT")==0) current_ptr
->stateTax
= current_ptr
->grossPay
* VT_TAX_RATE
; else if (strcmp(current_ptr
->taxState
,"CA")==0) current_ptr
->stateTax
= current_ptr
->grossPay
* CA_TAX_RATE
; else current_ptr->stateTax = current_ptr->grossPay * DEFAULT_TAX_RATE;
}
}
void calcFedTax(struct employee *head_ptr) {
struct employee *current_ptr;
for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
current_ptr->fedTax = current_ptr->grossPay * FED_TAX_RATE;
}
void calcNetPay(struct employee *head_ptr) {
struct employee *current_ptr;
for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next)
current_ptr->netPay = current_ptr->grossPay - current_ptr->stateTax - current_ptr->fedTax;
}
void calcEmployeeTotals(struct employee *head_ptr, struct totals *emp_totals_ptr) {
struct employee *current_ptr;
for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
emp_totals_ptr->total_wageRate += current_ptr->wageRate;
emp_totals_ptr->total_hours += current_ptr->hours;
emp_totals_ptr->total_overtimeHrs += current_ptr->overtimeHrs;
emp_totals_ptr->total_grossPay += current_ptr->grossPay;
emp_totals_ptr->total_stateTax += current_ptr->stateTax;
emp_totals_ptr->total_fedTax += current_ptr->fedTax;
emp_totals_ptr->total_netPay += current_ptr->netPay;
}
}
void calcEmployeeMinMax(struct employee *head_ptr, struct min_max *emp_minMax_ptr) {
struct employee *current_ptr = head_ptr;
if (!current_ptr) return;
emp_minMax_ptr->min_wageRate = emp_minMax_ptr->max_wageRate = current_ptr->wageRate;
emp_minMax_ptr->min_hours = emp_minMax_ptr->max_hours = current_ptr->hours;
emp_minMax_ptr->min_overtimeHrs = emp_minMax_ptr->max_overtimeHrs = current_ptr->overtimeHrs;
emp_minMax_ptr->min_grossPay = emp_minMax_ptr->max_grossPay = current_ptr->grossPay;
emp_minMax_ptr->min_stateTax = emp_minMax_ptr->max_stateTax = current_ptr->stateTax;
emp_minMax_ptr->min_fedTax = emp_minMax_ptr->max_fedTax = current_ptr->fedTax;
emp_minMax_ptr->min_netPay = emp_minMax_ptr->max_netPay = current_ptr->netPay;
for (current_ptr = current_ptr->next; current_ptr; current_ptr = current_ptr->next) {
if (current_ptr->wageRate < emp_minMax_ptr->min_wageRate) emp_minMax_ptr->min_wageRate = current_ptr->wageRate;
if (current_ptr->wageRate > emp_minMax_ptr->max_wageRate) emp_minMax_ptr->max_wageRate = current_ptr->wageRate;
if (current_ptr->hours < emp_minMax_ptr->min_hours) emp_minMax_ptr->min_hours = current_ptr->hours;
if (current_ptr->hours > emp_minMax_ptr->max_hours) emp_minMax_ptr->max_hours = current_ptr->hours;
if (current_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs) emp_minMax_ptr->min_overtimeHrs = current_ptr->overtimeHrs;
if (current_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs) emp_minMax_ptr->max_overtimeHrs = current_ptr->overtimeHrs;
if (current_ptr->grossPay < emp_minMax_ptr->min_grossPay) emp_minMax_ptr->min_grossPay = current_ptr->grossPay;
if (current_ptr->grossPay > emp_minMax_ptr->max_grossPay) emp_minMax_ptr->max_grossPay = current_ptr->grossPay;
if (current_ptr->stateTax < emp_minMax_ptr->min_stateTax) emp_minMax_ptr->min_stateTax = current_ptr->stateTax;
if (current_ptr->stateTax > emp_minMax_ptr->max_stateTax) emp_minMax_ptr->max_stateTax = current_ptr->stateTax;
if (current_ptr->fedTax < emp_minMax_ptr->min_fedTax) emp_minMax_ptr->min_fedTax = current_ptr->fedTax;
if (current_ptr->fedTax > emp_minMax_ptr->max_fedTax) emp_minMax_ptr->max_fedTax = current_ptr->fedTax;
if (current_ptr->netPay < emp_minMax_ptr->min_netPay) emp_minMax_ptr->min_netPay = current_ptr->netPay;
if (current_ptr->netPay > emp_minMax_ptr->max_netPay) emp_minMax_ptr->max_netPay = current_ptr->netPay;
}
}
//**************************************************************
// Print employee report
//**************************************************************
void printEmpReport(struct employee *head_ptr) {
struct employee *current_ptr;
printf("\nEmployee Payroll Report\n"); printf("----------------------------------------------------------\n"); for (current_ptr = head_ptr; current_ptr; current_ptr = current_ptr->next) {
printf("%s %s | Net Pay: $%.2f\n", current_ptr->empName.firstName,
current_ptr->empName.lastName,
current_ptr->netPay);
}
}
//**************************************************************
// Print totals and min/max statistics
//**************************************************************
void printEmpStatistics(struct totals *emp_totals_ptr, struct min_max *emp_minMax_ptr) {
printf("\nEmployee Totals and Statistics\n"); printf("----------------------------------------------------------\n"); printf("Total Gross Pay: $%.2f\n", emp_totals_ptr
->total_grossPay
); printf("Min Gross Pay: $%.2f | Max Gross Pay: $%.2f\n", emp_minMax_ptr
->min_grossPay
, emp_minMax_ptr
->max_grossPay
); }