//********************************************************
//
// Assignment 9 - Linked Lists
//
// Name: Anthony Principe
//
// Class: C Programming Fall 2025
//
// Date: 11/16/25
//
// Description: Program that figures out overtime and
// gross pay for each employee and prints the results.
// It also figures out state tax, federal tax, and net
// pay. At the end it prints totals, averages, and the
// min and max values.
//
// This version uses a linked list so the program can
// handle any number of employees. Each employee is
// stored in a node created with malloc.
//
//********************************************************
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
// set up common constants
#define STD_HOURS 40.0
#define OT_RATE 1.5
#define MA_TAX_RATE 0.05
#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 FIRST_NAME_SIZE 10
#define LAST_NAME_SIZE 10
#define TAX_STATE_SIZE 3
#define FED_TAX_RATE 0.25
// holds the first and last name
struct name
{
char firstName[FIRST_NAME_SIZE];
char lastName [LAST_NAME_SIZE];
};
// holds all employee info + pointer to next node
struct employee
{
struct name empName;
char taxState[TAX_STATE_SIZE];
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
float stateTax;
float fedTax;
float netPay;
struct employee * next; // next node in the list
};
// used to add totals together
struct totals
{
float total_wageRate;
float total_hours;
float total_overtimeHrs;
float total_grossPay;
float total_stateTax;
float total_fedTax;
float total_netPay;
};
// used to track min and max values
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
struct employee * getEmpData (void);
int isEmployeeSize (struct employee * head_ptr);
void calcOvertimeHrs (struct employee * head_ptr);
void calcGrossPay (struct employee * head_ptr);
void printHeader (void);
void printEmp (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 printEmpStatistics (struct totals * emp_totals_ptr,
struct min_max * emp_minMax_ptr,
int theSize);
int main ()
{
struct employee * head_ptr;
int theSize;
// hold all totals
struct totals employeeTotals = {0,0,0,0,0,0,0};
struct totals * emp_totals_ptr = &employeeTotals;
// hold all min and max values
struct min_max employeeMinMax = {0,0,0,0,0,0,0,
0,0,0,0,0,0,0};
struct min_max * emp_minMax_ptr = &employeeMinMax;
// get the linked list of employees
head_ptr = getEmpData();
// count how many employees were entered
theSize = isEmployeeSize(head_ptr);
if (theSize <= 0)
{
printf("\n\n**** There was no employee input to process ***\n"); }
else
{
// run all calculations
calcOvertimeHrs(head_ptr);
calcGrossPay(head_ptr);
calcStateTax(head_ptr);
calcFedTax(head_ptr);
calcNetPay(head_ptr);
calcEmployeeTotals(head_ptr, &employeeTotals);
calcEmployeeMinMax(head_ptr, &employeeMinMax);
// print everything
printHeader();
printEmp(head_ptr);
printEmpStatistics(&employeeTotals, &employeeMinMax, theSize);
}
printf("\n\n *** End of Program *** \n");
return 0;
}
//**************************************************************
// Function: getEmpData
//
// Purpose: Gets employee info from the user and builds the
// linked list one node at a time using malloc.
//**************************************************************
struct employee * getEmpData (void)
{
char answer[80];
int more_data = 1;
char value;
struct employee *current_ptr, *head_ptr;
// make first node
head_ptr
= (struct employee
*) malloc(sizeof(struct employee
)); current_ptr = head_ptr;
while (more_data)
{
printf ("\nEnter employee first name: "); scanf ("%s", current_ptr
->empName.
firstName);
printf ("\nEnter employee last name: "); scanf ("%s", current_ptr
->empName.
lastName);
printf ("\nEnter employee two character tax state: "); scanf ("%s", current_ptr
->taxState
);
printf("\nEnter employee clock number: "); scanf("%li", & current_ptr
->clockNumber
);
printf("\nEnter employee hourly wage: "); scanf("%f", & current_ptr
->wageRate
);
printf("\nEnter hours worked this week: "); scanf("%f", & current_ptr
->hours
);
printf("\nWould you like to add another employee? (y/n): ");
// check if user wants another employee
if (value != 'Y')
{
current_ptr->next = NULL;
more_data = 0;
}
else
{
// make next node
current_ptr->next =
(struct employee
*) malloc(sizeof(struct employee
));
current_ptr = current_ptr->next;
}
}
return head_ptr;
} // getEmpData
//**************************************************************
// Function: isEmployeeSize
//
// Purpose: Counts how many employees are in the list.
//**************************************************************
int isEmployeeSize (struct employee * head_ptr)
{
struct employee * current_ptr;
int theSize = 0;
if (head_ptr->empName.firstName[0] != '\0')
{
for (current_ptr = head_ptr;
current_ptr;
current_ptr = current_ptr->next)
{
++theSize;
}
}
return theSize;
} // isEmployeeSize
//**************************************************************
// Function: printHeader
//
// Purpose: Prints all the column labels.
//**************************************************************
void printHeader (void)
{
printf ("\n\n*** Pay Calculator ***\n");
printf("\n--------------------------------------------------------------"); printf("-------------------"); printf("\nName Tax Clock# Wage Hours OT Gross "); printf("\n--------------------------------------------------------------"); printf("-------------------");
} // printHeader
//**************************************************************
// Function: printEmp
//
// Purpose: Prints one row for each employee.
//**************************************************************
void printEmp (struct employee * head_ptr)
{
char name [FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
struct employee * current_ptr;
for (current_ptr = head_ptr;
current_ptr;
current_ptr = current_ptr->next)
{
// build full name
strcpy (name
, current_ptr
->empName.
firstName); strcat (name
, current_ptr
->empName.
lastName);
// print one row
printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f " "%7.2f %6.2f %7.2f %8.2f",
name, current_ptr->taxState, current_ptr->clockNumber,
current_ptr->wageRate, current_ptr->hours,
current_ptr->overtimeHrs, current_ptr->grossPay,
current_ptr->stateTax, current_ptr->fedTax,
current_ptr->netPay);
}
} // printEmp
//**************************************************************
// Function: calcOvertimeHrs
//
// Purpose: Figures out how many overtime hours were worked.
//**************************************************************
void calcOvertimeHrs (struct employee * head_ptr)
{
struct employee * current_ptr;
for (current_ptr = head_ptr;
current_ptr;
current_ptr = current_ptr->next)
{
if (current_ptr->hours > STD_HOURS)
current_ptr->overtimeHrs = current_ptr->hours - STD_HOURS;
else
current_ptr->overtimeHrs = 0;
}
} // calcOvertimeHrs
//**************************************************************
// Function: calcGrossPay
//
// Purpose: Figures out the normal pay + overtime pay.
//**************************************************************
void calcGrossPay (struct employee * head_ptr)
{
float theNormalPay;
float theOvertimePay;
struct employee * current_ptr;
for (current_ptr = head_ptr;
current_ptr;
current_ptr = current_ptr->next)
{
theNormalPay =
current_ptr->wageRate *
(current_ptr->hours - current_ptr->overtimeHrs);
theOvertimePay =
current_ptr->overtimeHrs *
(OT_RATE * current_ptr->wageRate);
current_ptr->grossPay = theNormalPay + theOvertimePay;
}
} // calcGrossPay
//**************************************************************
// Function: calcStateTax
//
// Purpose: Calculates state tax using the employee's state code.
//**************************************************************
void calcStateTax (struct employee * head_ptr)
{
struct employee * current_ptr;
for (current_ptr = head_ptr;
current_ptr;
current_ptr = current_ptr->next)
{
// convert to uppercase if needed
current_ptr
->taxState
[0] = toupper(current_ptr
->taxState
[0]); current_ptr
->taxState
[1] = toupper(current_ptr
->taxState
[1]);
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;
}
} // calcStateTax
//**************************************************************
// Function: calcFedTax
//
// Purpose: Federal tax is always 25% of gross pay.
//**************************************************************
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;
}
} // calcFedTax
//**************************************************************
// Function: calcNetPay
//
// Purpose: Net pay = gross pay minus taxes.
//**************************************************************
void calcNetPay (struct employee * head_ptr)
{
float theTotalTaxes;
struct employee * current_ptr;
for (current_ptr = head_ptr;
current_ptr;
current_ptr = current_ptr->next)
{
theTotalTaxes = current_ptr->stateTax + current_ptr->fedTax;
current_ptr->netPay = current_ptr->grossPay - theTotalTaxes;
}
} // calcNetPay
//**************************************************************
// Function: calcEmployeeTotals
//
// Purpose: Adds up all values to make a totals row.
//**************************************************************
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;
}
} // calcEmployeeTotals
//**************************************************************
// Function: calcEmployeeMinMax
//
// Purpose: Finds the lowest and highest numbers for each field.
//**************************************************************
void calcEmployeeMinMax (struct employee * head_ptr,
struct min_max * emp_minMax_ptr)
{
struct employee * current_ptr;
// start with first employee
current_ptr = head_ptr;
emp_minMax_ptr->min_wageRate = current_ptr->wageRate;
emp_minMax_ptr->min_hours = current_ptr->hours;
emp_minMax_ptr->min_overtimeHrs = current_ptr->overtimeHrs;
emp_minMax_ptr->min_grossPay = current_ptr->grossPay;
emp_minMax_ptr->min_stateTax = current_ptr->stateTax;
emp_minMax_ptr->min_fedTax = current_ptr->fedTax;
emp_minMax_ptr->min_netPay = current_ptr->netPay;
emp_minMax_ptr->max_wageRate = current_ptr->wageRate;
emp_minMax_ptr->max_hours = current_ptr->hours;
emp_minMax_ptr->max_overtimeHrs = current_ptr->overtimeHrs;
emp_minMax_ptr->max_grossPay = current_ptr->grossPay;
emp_minMax_ptr->max_stateTax = current_ptr->stateTax;
emp_minMax_ptr->max_fedTax = current_ptr->fedTax;
emp_minMax_ptr->max_netPay = current_ptr->netPay;
// move to the next employee
current_ptr = current_ptr->next;
// compare the rest of the employees
for (; 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;
}
} // calcEmployeeMinMax
//**************************************************************
// Function: printEmpStatistics
//
// Purpose: Prints totals, averages, and min/max rows.
//
//**************************************************************
void printEmpStatistics (struct totals * emp_totals_ptr,
struct min_max * emp_minMax_ptr,
int theSize)
{
printf("\n--------------------------------------------------------------"); printf("-------------------");
printf("\nTotals: %5.2f %5.1f %5.1f %7.2f " "%6.2f %7.2f %8.2f",
emp_totals_ptr->total_wageRate,
emp_totals_ptr->total_hours,
emp_totals_ptr->total_overtimeHrs,
emp_totals_ptr->total_grossPay,
emp_totals_ptr->total_stateTax,
emp_totals_ptr->total_fedTax,
emp_totals_ptr->total_netPay);
if (theSize > 0)
{
printf("\nAverages: %5.2f %5.1f %5.1f %7.2f " "%6.2f %7.2f %8.2f",
emp_totals_ptr->total_wageRate/theSize,
emp_totals_ptr->total_hours/theSize,
emp_totals_ptr->total_overtimeHrs/theSize,
emp_totals_ptr->total_grossPay/theSize,
emp_totals_ptr->total_stateTax/theSize,
emp_totals_ptr->total_fedTax/theSize,
emp_totals_ptr->total_netPay/theSize);
}
printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f " "%6.2f %7.2f %8.2f",
emp_minMax_ptr->min_wageRate,
emp_minMax_ptr->min_hours,
emp_minMax_ptr->min_overtimeHrs,
emp_minMax_ptr->min_grossPay,
emp_minMax_ptr->min_stateTax,
emp_minMax_ptr->min_fedTax,
emp_minMax_ptr->min_netPay);
printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f " "%6.2f %7.2f %8.2f",
emp_minMax_ptr->max_wageRate,
emp_minMax_ptr->max_hours,
emp_minMax_ptr->max_overtimeHrs,
emp_minMax_ptr->max_grossPay,
emp_minMax_ptr->max_stateTax,
emp_minMax_ptr->max_fedTax,
emp_minMax_ptr->max_netPay);
printf ("\n\nThe total employees processed was: %i\n", theSize
);
} // printEmpStatistics