Skip to content

Instantly share code, notes, and snippets.

@JesseKPhillips
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseKPhillips/6f15d9e35f989060adb6 to your computer and use it in GitHub Desktop.
Save JesseKPhillips/6f15d9e35f989060adb6 to your computer and use it in GitHub Desktop.
Provides the sequence of events for the USA 2014 Qualified Dividend and Capital Gain Tax Worksheet.
/**
* Provides the sequence of events for the USA 2014 Qualified Dividend and Capital Gain Tax Worksheet.
*
* This is license under Boost 1.0:
* http://www.boost.org/LICENSE_1_0.txt
*
* Do not rely on this software being correct, do yourself a favor and
* review the the logic.
*
* It relys on cmdln.interact found on github:
* https://github.com/JesseKPhillips/JPDLibs/tree/cmdln
*/
import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
import std.string;
import cmdln.interact;
struct Line {
private int[27] lineData;
int opIndex(int i) {
return lineData[i-1];
}
int opIndexAssign(int v, int i) {
return lineData[i-1] = v;
}
int opIndexAssign(double v, int i) {
import std.math : round;
return lineData[i-1] = round(v).to!int;
}
int[] opSlice() {
return lineData[];
}
}
void main() {
auto line = fillSheet();
writeln();
foreach(lineNumber, lineValue; line[])
writeln("Line %2s".format(lineNumber+1), ": ", lineValue.formatNum);
writeln();
writeln("Your owed Taxes: ", line[].back);
}
Line fillSheet() {
auto line = Line();
scope(success) line[].map!lossIsZero.copy(line[]);
line[1] = userInput!int("1. Enter the amount from Form 1040, line 43: ");
line[2] = userInput!int("2. Enter the amount from Form 1040, line 9b*: ");
if(userInput!bool("Are you filing Schedule D?*: "))
line[3] = userInput!int("3. Enter the smaller of line 15 or 16 of Schedule D: ");
else
line[3] = userInput!int("3. Enter the amount from Form 1040, line 13: ");
line[4] = line[2] + line[3];
if(userInput!bool("Are you filing Form 4952 (used to figure investment interest expense deduction): "))
line[5] = userInput!int("5. Enter any amount from line 4g of that form.");
else line[5] = 0;
line[6] = line[4] - line[5];
line[7] = line[1] - line[6];
auto status = ["Single", "Married Filing Separate", "Married Filing Jointly", "Head of House"];
auto statusSelection = menu!int("Are you: ", status);
if(statusSelection == 1)
line[8] = 36_900;
else if(statusSelection == 2)
line[8] = 73_800;
else if(statusSelection == 3)
line[8] = 73_800;
else if(statusSelection == 4)
line[8] = 49_400;
line[9] = [line[1], line[8]].reduce!min;
line[10] = [line[7], line[9]].reduce!min;
line[11] = line[9] - line[10];
line[12] = [line[1], line[6]].reduce!min;
line[13] = line[11];
line[14] = line[12] - line[13];
if(statusSelection == 1)
line[15] = 406_750;
else if(statusSelection == 2)
line[15] = 228_800;
else if(statusSelection == 3)
line[15] = 457_600;
else if(statusSelection == 4)
line[15] = 432_200;
line[16] = [line[1], line[15]].reduce!min;
line[17] = line[7] + line[11];
line[18] = line[16] - line[17];
line[19] = [line[14], line[18]].reduce!min;
line[20] = line[19] * 0.15;
line[21] = line[11] + line[19];
line[22] = line[12] - line[21];
line[23] = line[22] * 0.20;
if(line[7] < 100_000)
line[24] = userInput!int("24. Figure the tax on the amount on %s (Tax Table)".format(line[7].formatNum));
else
line[24] = userInput!int("24. Figure the tax on the amount on %s (Tax Computation Worksheet)".format(line[7].formatNum));
line[25] = line[20] + line[23] + line[24];
if(line[7] < 100_000)
line[26] = userInput!int("26. Figure the tax on the amount on %s (Tax Table)".format(line[1].formatNum));
else
line[26] = userInput!int("26. Figure the tax on the amount on %s (Tax Computation Worksheet)".format(line[1].formatNum));
line[27] = [line[25], line[26]].reduce!min;
return line;
}
auto lossIsZero(int num) {
if(num < 0)
return 0;
else
return num;
}
string formatNum(int num) {
auto snum = num.to!string;
return snum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment