// Assignment 10 - Employee Pay Calculator with Typedef and Macros
//
// Name: Felix Henriquez
//
// Class: C Programming, Fall 2025
//
// Date: November 23, 2025
//
// Description: This program extends the employee pay calculator by implementing
// typedef aliases for structures and macros for calculations.
// It processes employee data using linked lists, calculates
// overtime, gross pay, state tax, federal tax, and net pay.
// The program also computes totals, averages, and min/max values
// for all employees using macro-based calculations.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// ===========================
// MACRO DEFINITIONS
// ===========================
// Macro to calculate overtime hours
#define CALC_OT_HOURS(hours) ((hours) > 40.0 ? (hours) - 40.0 : 0.0)
// Macro to calculate regular hours
#define CALC_REG_HOURS(hours, ot_hours) ((hours) - (ot_hours))
// Macro to calculate gross pay
#define CALC_GROSS_PAY(reg_hours, ot_hours, wage) \
(((reg_hours) * (wage)) + ((ot_hours) * (wage) * 1.5))
// Macro to calculate state tax
#define CALC_STATE_TAX(gross, state) \
(strcmp(state, "MA") == 0 ? (gross) * 0.05 : \
strcmp(state, "VT") == 0 ? (gross) * 0.06 : \
strcmp(state, "NH") == 0 ? 0.00 : \
strcmp(state, "CA") == 0 ? (gross) * 0.07 : \
strcmp(state, "NY") == 0 ? (gross) * 0.08 : 0.00)
// Macro to calculate federal tax (25% of gross pay)
#define CALC_FED_TAX(gross) ((gross) * 0.25)
// Macro to calculate net pay
#define CALC_NET_PAY(gross, state_tax, fed_tax) \
((gross) - (state_tax) - (fed_tax))
// Fixed MIN and MAX macros
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
// ===========================
// TYPE DEFINITIONS
// ===========================
// Employee structure
typedef struct employee {
char first_name[21];
char last_name[21];
char tax_state[3];
char clock_number[7];
float wage_rate;
float hours;
float ot_hours;
float gross_pay;
float state_tax;
float fed_tax;
float net_pay;
struct employee* next;
} EMPLOYEE;
// Min/Max structure with typedef alias
typedef struct min_max {
float wage_rate;
float hours;
float ot_hours;
float gross_pay;
float state_tax;
float fed_tax;
float net_pay;
} MIN_MAX;
// Employee totals structure
typedef struct employee_totals {
float wage_rate;
float hours;
float ot_hours;
float gross_pay;
float state_tax;
float fed_tax;
float net_pay;
MIN_MAX min;
MIN_MAX max;
int count;
} EMPLOYEE_TOTALS;
// ===========================
// FUNCTION PROTOTYPES
// ===========================
EMPLOYEE* create_employee();
void calculate_employee_pay(EMPLOYEE* emp);
void calculate_employee_totals(EMPLOYEE_TOTALS* totals, const EMPLOYEE* emp);
void init_min_max(MIN_MAX* min_max);
void print_employee_data(const EMPLOYEE* emp);
void print_employee_totals(const EMPLOYEE_TOTALS* totals);
// ===========================
// FUNCTION IMPLEMENTATIONS
// ===========================
EMPLOYEE* create_employee() {
EMPLOYEE
* new_emp
= (EMPLOYEE
*)malloc(sizeof(EMPLOYEE
)); if (new_emp == NULL) {
printf("Memory allocation failed!\n"); }
new_emp->next = NULL;
return new_emp;
}
void calculate_employee_pay(EMPLOYEE* emp) {
// Calculate overtime hours using macro
emp->ot_hours = CALC_OT_HOURS(emp->hours);
// Calculate regular hours using macro
float reg_hours = CALC_REG_HOURS(emp->hours, emp->ot_hours);
// Calculate gross pay using macro
emp->gross_pay = CALC_GROSS_PAY(reg_hours, emp->ot_hours, emp->wage_rate);
// Calculate state tax using macro
emp->state_tax = CALC_STATE_TAX(emp->gross_pay, emp->tax_state);
// Calculate federal tax using macro
emp->fed_tax = CALC_FED_TAX(emp->gross_pay);
// Calculate net pay using macro
emp->net_pay = CALC_NET_PAY(emp->gross_pay, emp->state_tax, emp->fed_tax);
}
void init_min_max(MIN_MAX* min_max) {
min_max->wage_rate = 999999.0;
min_max->hours = 999999.0;
min_max->ot_hours = 999999.0;
min_max->gross_pay = 999999.0;
min_max->state_tax = 999999.0;
min_max->fed_tax = 999999.0;
min_max->net_pay = 999999.0;
}
void calculate_employee_totals(EMPLOYEE_TOTALS* totals, const EMPLOYEE* emp) {
totals->wage_rate += emp->wage_rate;
totals->hours += emp->hours;
totals->ot_hours += emp->ot_hours;
totals->gross_pay += emp->gross_pay;
totals->state_tax += emp->state_tax;
totals->fed_tax += emp->fed_tax;
totals->net_pay += emp->net_pay;
totals->count++;
// Update min calculations using MIN macro
totals->min.wage_rate = MIN(totals->min.wage_rate, emp->wage_rate);
totals->min.hours = MIN(totals->min.hours, emp->hours);
totals->min.ot_hours = MIN(totals->min.ot_hours, emp->ot_hours);
totals->min.gross_pay = MIN(totals->min.gross_pay, emp->gross_pay);
totals->min.state_tax = MIN(totals->min.state_tax, emp->state_tax);
totals->min.fed_tax = MIN(totals->min.fed_tax, emp->fed_tax);
totals->min.net_pay = MIN(totals->min.net_pay, emp->net_pay);
// Update max calculations using MAX macro
totals->max.wage_rate = MAX(totals->max.wage_rate, emp->wage_rate);
totals->max.hours = MAX(totals->max.hours, emp->hours);
totals->max.ot_hours = MAX(totals->max.ot_hours, emp->ot_hours);
totals->max.gross_pay = MAX(totals->max.gross_pay, emp->gross_pay);
totals->max.state_tax = MAX(totals->max.state_tax, emp->state_tax);
totals->max.fed_tax = MAX(totals->max.fed_tax, emp->fed_tax);
totals->max.net_pay = MAX(totals->max.net_pay, emp->net_pay);
}
void print_employee_data(const EMPLOYEE* emp) {
printf("%-19s %-2s %-6s %6.2f %5.1f %4.1f %7.2f %6.2f %6.2f %8.2f\n", emp->first_name, emp->tax_state, emp->clock_number,
emp->wage_rate, emp->hours, emp->ot_hours, emp->gross_pay,
emp->state_tax, emp->fed_tax, emp->net_pay);
}
void print_employee_totals(const EMPLOYEE_TOTALS* totals) {
printf("Totals: %24.2f %5.1f %4.1f %8.2f %6.2f %7.2f %8.2f\n", totals->wage_rate, totals->hours, totals->ot_hours, totals->gross_pay,
totals->state_tax, totals->fed_tax, totals->net_pay);
printf("Averages: %22.2f %5.1f %4.1f %8.2f %6.2f %7.2f %8.2f\n", totals->wage_rate / totals->count,
totals->hours / totals->count,
totals->ot_hours / totals->count,
totals->gross_pay / totals->count,
totals->state_tax / totals->count,
totals->fed_tax / totals->count,
totals->net_pay / totals->count);
printf("Minimum: %23.2f %5.1f %4.1f %8.2f %6.2f %7.2f %8.2f\n", totals->min.wage_rate, totals->min.hours, totals->min.ot_hours,
totals->min.gross_pay, totals->min.state_tax, totals->min.fed_tax,
totals->min.net_pay);
printf("Maximum: %23.2f %5.1f %4.1f %8.2f %6.2f %7.2f %8.2f\n", totals->max.wage_rate, totals->max.hours, totals->max.ot_hours,
totals->max.gross_pay, totals->max.state_tax, totals->max.fed_tax,
totals->max.net_pay);
}
// ===========================
// MAIN FUNCTION
// ===========================
int main() {
EMPLOYEE* head = NULL;
EMPLOYEE* tail = NULL;
EMPLOYEE_TOTALS totals = {0};
// Initialize min/max values
init_min_max(&totals.min);
totals.max.wage_rate = -999999.0;
totals.max.hours = -999999.0;
totals.max.ot_hours = -999999.0;
totals.max.gross_pay = -999999.0;
totals.max.state_tax = -999999.0;
totals.max.fed_tax = -999999.0;
totals.max.net_pay = -999999.0;
// Pre-defined employee data for ideone.com (no user input required)
char* first_names[] = {"Connie", "Mary", "Frank", "Jeff", "Anton"};
char* last_names[] = {"Cobol", "Apl", "Fortran", "Ada", "Pascal"};
char* tax_states[] = {"MA", "NH", "VT", "NY", "CA"};
char* clock_numbers[] = {"98401", "526488", "765349", "34645", "127615"};
float wage_rates[] = {10.60, 9.75, 10.50, 12.25, 8.35};
float hours[] = {51.0, 42.5, 37.0, 45.0, 40.0};
int employee_count = 5;
// Print program header
printf("*** Pay Calculator ***\n\n"); printf("---------------------------------------------------------------------------------\n"); printf("Name Tax Clock# Wage Hours OT Gross State Fed Net\n"); printf(" State Pay Tax Tax Pay\n"); printf("---------------------------------------------------------------------------------\n");
// Process all employees using linked list
for (int i = 0; i < employee_count; i++) {
EMPLOYEE* new_emp = create_employee();
// Set employee data
strcpy(new_emp
->first_name
, first_names
[i
]); strcpy(new_emp
->last_name
, last_names
[i
]); strcpy(new_emp
->tax_state
, tax_states
[i
]); strcpy(new_emp
->clock_number
, clock_numbers
[i
]); new_emp->wage_rate = wage_rates[i];
new_emp->hours = hours[i];
// Calculate pay using macros
calculate_employee_pay(new_emp);
// Add to linked list
if (head == NULL) {
head = new_emp;
tail = new_emp;
} else {
tail->next = new_emp;
tail = new_emp;
}
// Calculate totals and min/max values
calculate_employee_totals(&totals, new_emp);
// Print employee data
print_employee_data(new_emp);
}
printf("---------------------------------------------------------------------------------\n");
// Print summary statistics
print_employee_totals(&totals);
printf("\nThe total employees processed was: %d\n", totals.
count); printf("\n\n *** End of Program *** \n");
// Free allocated memory
EMPLOYEE* current = head;
while (current != NULL) {
EMPLOYEE* next = current->next;
current = next;
}
return 0;
}