1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C program for calculating tax brackets(no arrays)

  1. Nov 11, 2015 #1
    1. The problem statement, all variables and given/known data
    I have an assignment with the following requirements for the functions:
    1. Tax_Bracket_Identification. This function will identify the tax bracket. This function:
      • is of type int;
      • has one call-by-value argument (income);
      • uses nested if-else statements.
    2. Tax_Calculation. Will calculate the tax for each income scanned and:
      • is of type void;
      • has three arguments:
        • the income (call-by-value);
        • the tax bracket (call-by-value);
        • the tax (call-by-reference);
      • uses a switch case statement to calculate the income tax.
    3. PrintAll. This function will print the tax bracket and income tax. It:
      • is of type void;
      • has two arguments:
        • the tax bracket (call-by-value);
        • the income tax (call-by-value).

    2. Relevant equations

    3. The attempt at a solution
    Code (Text):

    #include <stdio.h>
    int taxBracketIdentification(int);
    void taxCalculation(int income, int taxbracket, int *tax);
    void printAll(int taxbracket, int tax);
    int taxbracket;

    void main() {
    int  incomenumber, tax, income;

    printf("Please type in the number of incomes to be processed. \n");
    scanf("%d", &incomenumber);
    printf("Please type in the income \n");
    scanf("%d", &income);

    printAll(tax, taxbracket);

    int taxBracketIdentification(int income) {
    int taxbracket;

    if (income < 10000) {
      taxbracket = 1;

      else if (income < 20000)
      taxbracket = 2;

      else if (income <30000)
      taxbracket = 3;
      else if (income < 50000)
      taxbracket = 4;

      else if (income < 100000)

      taxbracket = 5;

      else if (income > 100000)
      taxbracket = 6;


    void taxCalculation(int income, int taxbracket, int *tax) {

    switch(taxbracket) {
    case 1:
      *tax = (0.05 * income);
    case 2:
      *tax = 500 + 0.10*(income - 10000);
    case 3:
      *tax = 1500 + 0.15*(income-20000);
    case 4:
      *tax = 3000 + 0.20*(income-30000);
    case 5:
      *tax = 7000 + 0.25*(income-50000);
    case 6:
      *tax = 19500  + 0.30*(income-10000);


    void printAll(int taxbracket, int tax)

      printf("Your tax bracket is: \t %d \n", taxbracket);
      printf("Your tax is \t %d \n", tax);


    Why is it telling me that there is an undefined reference to printAll?
  2. jcsd
  3. Nov 11, 2015 #2


    Staff: Mentor

    If you're showing C code, use [code=c] instead of just plain [code] for the opening tag.

    Also, the code below doesn't have any indentation, which makes it hard to spot obvious errors.
    It looks to me like you have an extra right brace - }. That could be throwing the compiler off, resulting in the error you see. If that's not it, please give us the exact error message, which will have a line number.

    Also, I see a bug in your code. What happens in the income is $100,000?
  4. Nov 11, 2015 #3
    Okay i changed it to income >= 100000 over 10k, that bug shouldn't occur anymore.

    It compuiles fine but now it is telling me my tax bracket is 39 and my tax is 0 lol... what is going on here?
  5. Nov 11, 2015 #4
    and how do i get multiple inputs from the user? (say up to 3) without using arrays?
  6. Nov 11, 2015 #5


    Staff: Mentor

    Your main() function needs work. In it, you read incomenumber and income from the user, and then call printAll(), passing the uninitialized (hence garbage) tax value and taxbracket, a global, so is initialized to 0. printAll() merely displays a garbage value (tax) and 0 for taxbracket.

    1. Why is taxbracket a global variable?
    2. Why aren't you calling taxBracketIdentification() and taxCalculation()?
  7. Nov 11, 2015 #6


    Staff: Mentor

    Use a loop.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: C program for calculating tax brackets(no arrays)