/****************************************************************************** * This program computes federal income tax for single taxpayers. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include using namespace std; int main(int argc, char **argv) { double income = 0.; double income_tax = 0.; if (argc == 2) { income = Utils::stodWithDefault(string(argv[1]), 0); } else { cout << fmt::format("Syntax: {0:s} income", argv[0]) << endl; exit(1); } if (income <= 9875.) { income_tax += income * 0.10; } else { income_tax += 9875. * 0.10; if (income <= 40125.) { income_tax += (income - 9875.) * 0.12; } else { income_tax += (40125. - 9875.) * 0.12; if (income <= 85525.) { income_tax += (income - 40125.) * 0.22; } else { income_tax += (85525. - 40125.) * 0.22; if (income <= 163300.) { income_tax += (income - 85525.) * 0.24; } else { income_tax += (163300. - 85525.) * 0.24; if (income <= 207350.) { income_tax += (income - 163300.) * 0.32; } else { income_tax += (207350. - 163300.) * 0.32; if (income <= 518400.) { income_tax += (income - 207350.) * 0.35; } else { income_tax += (518400. - 207350.) * 0.35; if (income > 518400.) { income_tax += (income - 518400.) * 0.37; } } } } } } } cout << fmt::format("Federal Income Tax: ${0:.2f}", income_tax) << endl; return 0; }