marks@ihuxx.UUCP (08/25/83)
#TAX - a program to figure US federal withholding tax. # #simply save this file and execute as a shell procedure echo extracting: echo tax.c cat > tax.c <<'NEWFILE' #include <stdio.h> /* taxpayer class modifiers - * used to modify the following arrays' column index * that initially equates to a married, monthly paid * person. * * there are four taxpayer classes * single, paid weekly (0) * married, paid weekly (1) * single, paid monthly (2) * married, paid monthly (3) */ #define MARRIED 1 /* filing status */ #define MONTHLY 2 /* paid monthly */ #define NOofCLASSES 4 /* 0+0, 0+1, 2+0, and 2+1 */ /* * There are 7 tax brackets. */ #define NOofBRACKETS 7 /* * floor[][] and ceiling[][] give the lower * and upper bounds, repectively, on taxable * wages for a particular tax bracket (bracket[][]). * * tax[][] is the base tax for the associated bracket. */ double floor[ NOofBRACKETS ][ NOofCLASSES ] = { 27.00, 46.00, 117.00, 200.00, 79.00, 185.00, 342.00, 800.00, 183.00, 369.00, 792.00, 1598.00, 277.00, 454.00, 1200.00, 1967.00, 423.00, 556.00, 1833.00, 2408.00, 525.00, 658.00, 2317.00, 2850.00, 637.00, 862.00, 2758.00, 3733.00 }; /* MAXGROSS is only used as a place holder in the * array and has no affect on the tax calculation. * * It should be greater than the largest ceiling. */ #define MAXGROSS 9999.00 double ceiling[ NOofBRACKETS ][ NOofCLASSSES ] = { 79.00, 185.00, 342.00, 800.00, 183.00, 369.00, 792.00, 1598.00, 277.00, 454.00, 1200.00, 1967.00, 423.00, 556.00, 1833.00, 2408.00, 525.00, 658.00, 2317.00, 2850.00, 637.00, 862.00, 2758.00, 3733.00, MAXGROSS, MAXGROSS, MAXGROSS, MAXGROSS }; double baseTax[ NOofBRACKETS ][ NOofCLASSES ] = { 0.00, 0.00, 0.00, 0.00, 6.24, 16.68, 27.00, 72.00, 21.84, 47.96, 94.50, 207.66, 39.70, 66.66, 172.02, 288.84, 76.20, 92.16, 330.27, 399.09, 109.80, 120.72, 475.47, 522.85, 144.48, 188.04, 625.41, 814.24 }; double bracket[ NOofBRACKETS ][ NOofCLASSES ] = { .12, .12, .12, .12, .15, .17, .15, .17, .19, .22, .19, .22, .25, .25, .25, .25, .30, .28, .30, .28, .34, .33, .34, .33, .37, .37, .37, .37 }; #define EXEMPTION 1000.00 main(argc, argv) int argc; char *argv[]; { extern char *optarg; extern int optind; double gross = 1000, net, tax, taxw; int payperiods = 12, nexemptions = 2, j = MARRIED + MONTHLY; int i = 0, netflag = 0; char c; /* * The above initial values represent a married * taxpayer paid a monthly gross income of $1000. */ while ((c = getopt(argc, argv, "e:g:np:s:")) != EOF) { switch (c) { case 'e': sscanf(optarg, "%d", &nexemptions); break; case 'g': sscanf(optarg, "%f", &gross); break; case 'n': ++netflag; break; case 'p': if (*optarg == 'w') { payperiods = 52; j -= MONTHLY; } break; case 's': if (*optarg == 's') { j -= MARRIED; } break; default : fprintf(stderr, "tax: bad option\n"); exit(1); } } if (optind == 1) { usage(); exit(1); } if (gross > 200) { taxw = gross - (nexemptions * EXEMPTION / payperiods); i = 0; while (taxw < floor[i][j] || taxw > ceiling[i][j]) { /* * I choose not to limit the maximum taxable wage * since others may be more fortunate than myself ;-) * Rather, we just jump out of the loop when the * taxable wage exceeds the maximum and just use * the maximum values for the bracket. */ if (i == (NOofBRACKETS - 1)) break; else ++i; } tax = baseTax[i][j] + ((taxw - floor[i][j]) * bracket[i][j]); } else { tax = 0; } fprintf(stdout, "%.2f\n", tax); if (netflag) fprintf(stdout, "-n%.2f\n", (gross - tax)); exit(0); } usage() { fprintf(stdout, "usage: tax [-g grossPay] [-e numberOfExemptions]\n"); fprintf(stdout, " [-n] [-p monthly | weekly]\n"); fprintf(stdout, " [-s married | single]\n"); } NEWFILE echo extracting: echo tax.1 cat > tax.1 <<'NEWFILE' .TH TAX 1 .SH NAME tax \- Calculate federal withholding tax .SH SYNOPSIS .B tax [ option ] .SH DESCRIPTION .I Tax takes command line inputs, calculates a value for federal withholding tax, and writes the result to the standard output. .PP The following options are interpreted by .I tax . .TP 8 .B \-g G results in .B G being interpretted as the gross pay for the calculation. .TP .TP 8 .B \-e E results in .B E being interpretted as the number of exemptions. The gross pay will be reduced by the number of exemptions multiplied by the exemption amount and divided by the pay period. .TP .TP 8 .B \-n results in the string .B "-n N" being written to the standard output. .B N is the net pay (gross pay - withholding). .TP .TP 8 .B \-p The argument following the .B \-p flag determines the pay period. Allowable values are .B monthly (default) or .B weekly. .TP .TP 8 .B \-s The argument following the .B \-s flag determines the filing status. Allowable values are .B married (default) or .B single. .SH EXAMPLE .RS 10 tax -g 5000 -e 3 -p w -s single .RE .sp will output the withholding tax for a single taxpayer paid $5000/week (a high-roller) who has 3 exemptions. .SH DIAGNOSTICS The diagnostics produced by .B tax should be self-explanatory. .SH PROVIDER Mark Wm. Beckner NEWFILE