#include <stdio.h>
#include <stdlib.h>
// Define a struct to hold tax table entries
struct TaxEntry {
int income_min; // "At least" income
int income_max; // "But less than" income
int tax_single; // Tax for Single or Married Filing Separately
int tax_mfj; // Tax for Married Filing Jointly
int tax_hoh; // Tax for Head of Household or Qualifying Surviving Spouse
};
// Function to initialize the tax table with sample data from Tax Table 2
void loadTaxTable(struct TaxEntry taxTable[], int *size) {
// Sample data based on typical Oregon Tax Table 2 format
// These are illustrative values - replace with actual data from your PDF
taxTable[0] = (struct TaxEntry){0, 500, 0, 0, 0};
taxTable[1] = (struct TaxEntry){500, 1000, 24, 24, 24};
taxTable[2] = (struct TaxEntry){1000, 1500, 48, 48, 48};
taxTable[3] = (struct TaxEntry){1500, 2000, 71, 71, 71};
taxTable[4] = (struct TaxEntry){2000, 2500, 95, 95, 95};
// Add more entries as needed up to the table's end
*size = 5; // Update this based on actual number of entries
}
// Function to print the tax table
void printTaxTable(struct TaxEntry taxTable[], int size) {
printf("\nOregon Tax Table 2 (2024)\n");
printf("Income Range\t\tSingle/MFS\tMFJ\tHOH/QSS\n");
printf("------------------------------------------------\n");
for (int i = 0; i < size; i++) {
printf("$%d - $%d\t\t$%d\t\t$%d\t$%d\n",
taxTable[i].income_min,
taxTable[i].income_max,
taxTable[i].tax_single,
taxTable[i].tax_mfj,
taxTable[i].tax_hoh);
}
}
// Function to look up tax based on income and filing status
int calculateTax(struct TaxEntry taxTable[], int size, int income, char status) {
for (int i = 0; i < size; i++) {
if (income >= taxTable[i].income_min && income < taxTable[i].income_max) {
switch (status) {
case 'S': // Single or Married Filing Separately
case 'M':
return taxTable[i].tax_single;
case 'J': // Married Filing Jointly
return taxTable[i].tax_mfj;
case 'H': // Head of Household or Qualifying Surviving Spouse
return taxTable[i].tax_hoh;
default:
printf("Invalid filing status\n");
return -1;
}
}
}
printf("Income out of table range\n");
return -1;
}
int main() {
// Define array of structs with enough space for the table
struct TaxEntry taxTable[100]; // Adjust size based on actual table length
int tableSize = 0;
// Load the tax table
loadTaxTable(taxTable, &tableSize);
// Print the table
printTaxTable(taxTable, tableSize);
// Example tax calculation
int income = 1200;
char filingStatus = 'S'; // S=Single, M=MFS, J=MFJ, H=HOH
int tax = calculateTax(taxTable, tableSize, income, filingStatus);
if (tax >= 0) {
printf("\nTax for income $%d (Filing Status: %c) = $%d\n",
income, filingStatus, tax);
}
return 0;
}