/****************************************************************************** * This program computes federal income tax. * * 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.; string status = "S"; double income_tax = 0.; if (argc == 3) { income = Utils::stodWithDefault(string(argv[1]), 0); status = string(argv[2]); } else { cout << fmt::format("Syntax: {0:s} income S|M|H", argv[0]) << endl; exit(1); } if (status == "H") { if (income <= 14100.) { income_tax += income * 0.10; } else { income_tax += 14100. * 0.10; if (income <= 53700.) { income_tax += (income - 14100.) * 0.12; } else { income_tax += (53700. - 14100.) * 0.12; if (income <= 85500.) { income_tax += (income - 53700.) * 0.22; } else { income_tax += (85500. - 53700.) * 0.22; if (income <= 163300.) { income_tax += (income - 85500.) * 0.24; } else { income_tax += (163300. - 85500.) * 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; } } } } } } } } else if (status == "M") { if (income <= 19750.) { income_tax += income * 0.10; } else { income_tax += 19750. * 0.10; if (income <= 80250.) { income_tax += (income - 19750.) * 0.12; } else { income_tax += (80250. - 19750.) * 0.12; if (income <= 171050.) { income_tax += (income - 80250.) * 0.22; } else { income_tax += (171050. - 80250.) * 0.22; if (income <= 326600.) { income_tax += (income - 171050.) * 0.24; } else { income_tax += (326600. - 171050.) * 0.24; if (income <= 414700.) { income_tax += (income - 326600.) * 0.32; } else { income_tax += (414700. - 326600.) * 0.32; if (income <= 622050.) { income_tax += (income - 414700.) * 0.35; } else { income_tax += (622050. - 414700.) * 0.35; if (income > 622050.) { income_tax += (income - 622050.) * 0.37; } } } } } } } } else { 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; }