Bifalgorithm post · Computer science one · Life & Taxes

How can conditional statements be used to build a life and taxes program?

How can conditional statements be used to build a life and taxes program? (Computer science one · Life & Taxes) — "Let’s adapt the conditional statements we de…

Ideas in this flowchart

  • Adaptar las sentencias condicionales a un programa completo en C
  • Establecer las variables y leer los datos del usuario
  • Declarar income, baseTax, numChildren, credit y totalTax
  • Leer el ingreso bruto ajustado del usuario
  • Leer el número de hijos del usuario
  • Comprobar si income o numChildren son negativos
  • Mostrar «Invalid inputs» y terminar el programa con exit(1)
  • Calcular el impuesto mediante una serie de if-else-if ordenada por rangos crecientes
  • Si income <= 18150, calcular baseTax como income * .10
  • Si income <= 73800, calcular baseTax como 1815 + (income - 18150) * .15
  • Para el rango siguiente, comprobar income <= 148850 y aplicar su cálculo correspondiente
  • En el caso final, calcular baseTax como 127962.50 + (income - 457600) * .396
Feed/

How can conditional statements be used to build a life and taxes program?

No cover

Channel

Computer science one

1 page

"Let’s adapt the conditional statements we developed in Section 3.6.4 into a full C program. The first thing we need to do is establish the variables we’ll need and read them in from the user. At the same time we can check for bad input (negative values) for both the inputs.\n\n1 double income, baseTax, numChildren, credit, totalTax;\n\n2\n\n3 printf(\"Please enter your Adjusted Gross Income: \");\n\n4 scanf(\"%lf\", &income);\n\n5\n\n6 printf(\"How many children do you have?\");\n\n7 scanf(\"%d\", &numChildren);\n\n8\n\n9 if(income < 0 || numChildren < 0) {\n\n10 printf(\"Invalid inputs\");\n\n11 exit(1);\n\n12 }\n\nNext, we can code a series of if-else-if statements for the income range. By placing the ranges in increasing order, we only need to check the upper bounds just as in the original example.\n\n1 if(income <= 18150) {\n\n2 baseTax = income * .10;\n\n3 } else if(income <= 73800) {\n\n4 baseTax = 1815 + (income - 18150) * .15;\n\n5 } else if(income <= 148850) {\n\n6 ...\n\n7 } else {\n\n8 baseTax = 127962.50 + (income - 457600) * .396;\n\n9 }"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.