# C program for calculating tax brackets(no arrays)

1. Nov 11, 2015

### HoojaMan33

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() {

printf("Please type in the number of incomes to be processed. \n");
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) {

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

}

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. Nov 11, 2015

### 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?

3. Nov 11, 2015

### HoojaMan33

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?

4. Nov 11, 2015

### HoojaMan33

and how do i get multiple inputs from the user? (say up to 3) without using arrays?

5. Nov 11, 2015

### 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()?

6. Nov 11, 2015

Use a loop.