Concept
How can conditionals calculate tax brackets, credits, and total tax?
ComputerScienceOne / Quadratic Roots Revisited
"16.3. Examples\n\n1 if(baseTax - credit >= 0) {\n\n2 totalTax = baseTax - credit;\n\n3 } else {\n\n4 totalTax = 0;\n\n5 }\n\nThe full program is presented in Code Sample 16.3.\n\n16.3.3. Quadratic Roots Revisited\n\n1 #include <stdlib.h>\n\n2 #include <stdio.h>\n\n3\n\n4 int main(int argc, char **argv) {\n\n5\n\n6 double income, baseTax, credit, totalTax;\n\n7 int numChildren;\n\n8\n\n9 //prompt for income from the user\n\n10 printf(\"Please enter your Adjusted Gross Income: \");\n\n11 scanf(\"%lf\", &income);\n\n12\n\n13 //prompt for children\n\n14 printf(\"How many children do you have?\");\n\n15 scanf(\"%d\", &numChildren);\n\n16\n\n17 if(income < 0 || numChildren < 0) {\n\n18 printf(\"Invalid inputs\");\n\n19 exit(1);\n\n20 }\n\n21\n\n22 if(income <= 18150) {\n\n23 baseTax = income * .10;\n\n24 } else if(income <= 73800) {\n\n25 baseTax = 1815 + (income -18150) * .15;\n\n26 } else if(income <= 148850) {\n\n27 baseTax = 10162.50 + (income - 73800) * .25;\n\n28 } else if(income <= 225850) {\n\n29 baseTax = 28925.00 + (income - 148850) * .28;\n\n30 } else if(income <= 405100) {\n\n31 baseTax = 50765.00 + (income - 225850) * .33;\n\n32 } else if(income <= 457600) {\n\n33 baseTax = 109587.50 + (income - 405100) * .35;\n\n34 } else {\n\n35 baseTax = 127962.50 + (income - 457600) * .396;\n\n36 }\n\n37\n\n38 if(numChildren <= 3) {\n\n39 credit = numChildren * 1000;\n\n40 } else {\n\n41 credit = 3000;\n\n42 }\n\n43\n\n44 if(baseTax - credit >= 0) {\n\n45 totalTax = baseTax - credit;\n\n46 } else {\n\n47 totalTax = 0;\n\n48 }\n\n49\n\n50 printf(\"AGI: $%10.2f\n\n\", income);\n\n51 printf(\"Tax: $%10.2f\n\n\", baseTax);\n\n52 printf(\"Credit: $%10.2f\n\n\", credit);\n\n53 printf(\"Tax Liability: $%10.2f\n\n\", totalTax);\n\n54\n\n55 return 0;\n\n56 } Code Sample 16.3.: Tax Program in C"
Related Ideas
- How can conditionals prevent a calculated tax liability from becoming negative?ComputerScienceOne · Quadratic Roots Revisited
- How can conditional statements be used to build a life and taxes program?ComputerScienceOne · Life & Taxes
- How is the child tax credit calculated and limited by total tax liability?ComputerScienceOne · Life & Taxes
- How can if-else-if statements calculate tax across increasing income ranges?ComputerScienceOne · Life & Taxes
- How can PHP conditionals validate income and calculate life and taxes?ComputerScienceOne · Life & Taxes
- How can a Java program read income and children inputs while rejecting negative values?ComputerScienceOne · Life & Taxes
- How are if, if-else, and if-else-if statements written in C?ComputerScienceOne · If, If-Else, If-Else-If Statements
- How do if, if-else, and if-else-if statements work in PHP?ComputerScienceOne · If, If-Else, If-Else-If Statements