//***************************************************************
// Name: John Semenuk
// Course: Spring 2026 C Programming
// Date: 04/05/2026
// Assignment: 8 - Employee Payroll Calculator (Pointer Version)
//
//***************************************************************
//
// Description:
// This program calculates employee payroll including gross pay,
// state and federal taxes, and net pay. It also computes totals,
// averages, minimum, and maximum values for all employees.
//
//***************************************************************
#include <stdio.h>
#include <string.h>
#include <math.h> // Needed for rounding
#define NUM_EMPL 5
//********************************************************
// Structure Definitions
//********************************************************
struct name {
char first[20]; // First name of employee
char last[20]; // Last name of employee
};
struct employee {
struct name empName; // Employee name
char state[3]; // Tax state
int clockNum; // Employee clock number
float wage; // Hourly wage
float hours; // Hours worked
float overtime; // Overtime hours
float grossPay; // Gross pay
float stateTax; // State tax
float fedTax; // Federal tax
float netPay; // Net pay
};
struct totals {
float totalWage;
float totalHours;
float totalOT;
float totalGross;
float totalStateTax;
float totalFedTax;
float totalNetPay;
};
struct min_max {
float minWage;
float maxWage;
float minHours;
float maxHours;
float minOT;
float maxOT;
float minGross;
float maxGross;
float minStateTax;
float maxStateTax;
float minFedTax;
float maxFedTax;
float minNet;
float maxNet;
};
//********************************************************
// Function Prototypes (using pointers)
//********************************************************
void getHours(struct employee *emp_ptr);
float getStateTax(char *state, float gross);
void calcEmployeeTotals(struct employee *emp_ptr, struct totals *totals_ptr);
void calcEmployeeMinMax(struct employee *emp_ptr, struct min_max *minMax_ptr);
void printHeader(void);
void printEmp(struct employee *emp_ptr);
void printSummary(struct totals *totals_ptr, struct min_max *minMax_ptr);
//********************************************************
// Main Function
//********************************************************
int main() {
// Initialize employee data
struct employee employeeData[NUM_EMPL] = {
{ {"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 }
};
// Pointer to the array of employee structures
struct employee *emp_ptr = employeeData;
// Set up structure to store totals and initialize all to zero
struct totals employeeTotals = {0,0,0,0,0,0,0};
struct totals *totals_ptr = &employeeTotals;
// Set up structure to store min and max values and initialize all to zero
struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
struct min_max *minMax_ptr = &employeeMinMax;
//********************************************************
// Input hours for each employee
//********************************************************
for (int i = 0; i < NUM_EMPL; i++) {
getHours(emp_ptr + i);
}
//********************************************************
// Calculate totals and min/max
//********************************************************
calcEmployeeTotals(emp_ptr, totals_ptr);
calcEmployeeMinMax(emp_ptr, minMax_ptr);
//********************************************************
// Print Reports
//********************************************************
printf("\nEmployee Payroll Report\n"); printf("----------------------------------------------------------\n"); for (int i = 0; i < NUM_EMPL; i++) {
printf("%s %s | Net Pay: %.2f\n", (emp_ptr + i)->empName.first,
(emp_ptr + i)->empName.last,
(emp_ptr + i)->netPay);
}
printf("\nTotal Net Pay: %.2f\n", totals_ptr
->totalNetPay
); printf("Minimum Net Pay: %.2f\n", minMax_ptr
->minNet
); printf("Maximum Net Pay: %.2f\n", minMax_ptr
->maxNet
);
printf("\n*** Pay Calculator ***\n\n");
printHeader();
for (int i = 0; i < NUM_EMPL; i++) {
printEmp(emp_ptr + i);
}
printSummary(totals_ptr, minMax_ptr);
return 0;
}
//********************************************************
// Function Definitions
//********************************************************
// Function to get hours worked for an employee
void getHours(struct employee *emp_ptr) {
printf("Enter hours worked for employee #%06d: ", emp_ptr
->clockNum
); scanf("%f", &emp_ptr
->hours
);
// Calculate overtime if hours > 40
if (emp_ptr->hours > 40) {
emp_ptr->overtime = emp_ptr->hours - 40;
} else {
emp_ptr->overtime = 0;
}
// Calculate gross pay
emp_ptr->grossPay = (emp_ptr->hours - emp_ptr->overtime) * emp_ptr->wage
+ emp_ptr->overtime * emp_ptr->wage * 1.5;
// Calculate taxes and net pay
emp_ptr->stateTax = getStateTax(emp_ptr->state, emp_ptr->grossPay);
emp_ptr->fedTax = 0.25 * emp_ptr->grossPay;
emp_ptr->netPay = emp_ptr->grossPay - emp_ptr->stateTax - emp_ptr->fedTax;
}
// Function to get state tax based on state abbreviation
float getStateTax(char *state, float gross) {
if (strcmp(state
, "NH") == 0) return 0.0; if (strcmp(state
, "MA") == 0) return gross
* 0.05; if (strcmp(state
, "VT") == 0) return gross
* 0.06; if (strcmp(state
, "NY") == 0) return gross
* 0.08; if (strcmp(state
, "CA") == 0) return gross
* 0.07; return 0.0; // Default
}
// Function to calculate totals for all employees
void calcEmployeeTotals(struct employee *emp_ptr, struct totals *totals_ptr) {
for (int i = 0; i < NUM_EMPL; i++) {
totals_ptr->totalWage += (emp_ptr + i)->wage;
totals_ptr->totalHours += (emp_ptr + i)->hours;
totals_ptr->totalOT += (emp_ptr + i)->overtime;
totals_ptr->totalGross += (emp_ptr + i)->grossPay;
totals_ptr->totalStateTax += (emp_ptr + i)->stateTax;
totals_ptr->totalFedTax += (emp_ptr + i)->fedTax;
totals_ptr->totalNetPay += (emp_ptr + i)->netPay;
}
}
// Function to calculate min/max values for all employees
void calcEmployeeMinMax(struct employee *emp_ptr, struct min_max *minMax_ptr) {
minMax_ptr->minWage = minMax_ptr->maxWage = emp_ptr->wage;
minMax_ptr->minHours = minMax_ptr->maxHours = emp_ptr->hours;
minMax_ptr->minOT = minMax_ptr->maxOT = emp_ptr->overtime;
minMax_ptr->minGross = minMax_ptr->maxGross = emp_ptr->grossPay;
minMax_ptr->minStateTax = minMax_ptr->maxStateTax = emp_ptr->stateTax;
minMax_ptr->minFedTax = minMax_ptr->maxFedTax = emp_ptr->fedTax;
minMax_ptr->minNet = minMax_ptr->maxNet = emp_ptr->netPay;
for (int i = 1; i < NUM_EMPL; i++) {
struct employee *e = emp_ptr + i;
if (e->wage < minMax_ptr->minWage) minMax_ptr->minWage = e->wage;
if (e->wage > minMax_ptr->maxWage) minMax_ptr->maxWage = e->wage;
if (e->hours < minMax_ptr->minHours) minMax_ptr->minHours = e->hours;
if (e->hours > minMax_ptr->maxHours) minMax_ptr->maxHours = e->hours;
if (e->overtime < minMax_ptr->minOT) minMax_ptr->minOT = e->overtime;
if (e->overtime > minMax_ptr->maxOT) minMax_ptr->maxOT = e->overtime;
if (e->grossPay < minMax_ptr->minGross) minMax_ptr->minGross = e->grossPay;
if (e->grossPay > minMax_ptr->maxGross) minMax_ptr->maxGross = e->grossPay;
if (e->stateTax < minMax_ptr->minStateTax) minMax_ptr->minStateTax = e->stateTax;
if (e->stateTax > minMax_ptr->maxStateTax) minMax_ptr->maxStateTax = e->stateTax;
if (e->fedTax < minMax_ptr->minFedTax) minMax_ptr->minFedTax = e->fedTax;
if (e->fedTax > minMax_ptr->maxFedTax) minMax_ptr->maxFedTax = e->fedTax;
if (e->netPay < minMax_ptr->minNet) minMax_ptr->minNet = e->netPay;
if (e->netPay > minMax_ptr->maxNet) minMax_ptr->maxNet = e->netPay;
}
}
// Function to print table header
void printHeader(void) {
printf("---------------------------------------------------------------------------------\n"); printf("Name Tax Clock# Wage Hours OT Gross State Fed Net\n"); printf(" State Pay Tax Tax Pay\n"); printf("---------------------------------------------------------------------------------\n"); }
// Function to print individual employee
void printEmp(struct employee *emp_ptr) {
printf("%-15s %-15s %2s %06d %5.2f %5.1f %5.1f %7.2f %6.2f %6.2f %7.2f\n", emp_ptr->empName.first,
emp_ptr->empName.last,
emp_ptr->state,
emp_ptr->clockNum,
emp_ptr->wage,
emp_ptr->hours,
emp_ptr->overtime,
emp_ptr->grossPay,
emp_ptr->stateTax,
emp_ptr->fedTax,
emp_ptr->netPay);
}
// Function to print totals, averages, min/max
void printSummary(struct totals *totals_ptr, struct min_max *minMax_ptr) {
printf("---------------------------------------------------------------------------------\n"); printf("Totals: %.2f %5.1f %5.1f %7.2f %6.2f %6.2f %7.2f\n", totals_ptr->totalWage,
totals_ptr->totalHours,
totals_ptr->totalOT,
totals_ptr->totalGross,
totals_ptr->totalStateTax,
totals_ptr->totalFedTax,
totals_ptr->totalNetPay);
printf("Averages: %.2f %5.1f %5.1f %7.2f %6.2f %6.2f %7.2f\n", totals_ptr->totalWage / NUM_EMPL,
totals_ptr->totalHours / NUM_EMPL,
totals_ptr->totalOT / NUM_EMPL,
totals_ptr->totalGross / NUM_EMPL,
totals_ptr->totalStateTax / NUM_EMPL,
totals_ptr->totalFedTax / NUM_EMPL,
totals_ptr->totalNetPay / NUM_EMPL);
printf("Minimum: %.2f %5.1f %5.1f %7.2f %6.2f %6.2f %7.2f\n", minMax_ptr->minWage,
minMax_ptr->minHours,
minMax_ptr->minOT,
minMax_ptr->minGross,
minMax_ptr->minStateTax,
minMax_ptr->minFedTax,
minMax_ptr->minNet);
printf("Maximum: %.2f %5.1f %5.1f %7.2f %6.2f %6.2f %7.2f\n", minMax_ptr->maxWage,
minMax_ptr->maxHours,
minMax_ptr->maxOT,
minMax_ptr->maxGross,
minMax_ptr->maxStateTax,
minMax_ptr->maxFedTax,
minMax_ptr->maxNet);
}