C program for calculating tax brackets(no arrays)

In summary: For example:for (int i = 0; i < 3; i++) { printf("Please enter income: "); scanf("%d", &income); // call taxBracketIdentification and taxCalculation // output results}
  • #1
HoojaMan33
15
0

Homework Statement


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).

Homework Equations

The Attempt at a Solution


Code:
#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) {

(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?
 
Physics news on Phys.org
  • #2
HoojaMan33 said:

Homework Statement


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).

Homework Equations

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.
HoojaMan33 said:

The Attempt at a Solution


Code:
#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) {

(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?
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
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
and how do i get multiple inputs from the user? (say up to 3) without using arrays?
 
  • #5
HoojaMan33 said:
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?
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
HoojaMan33 said:
and how do i get multiple inputs from the user? (say up to 3) without using arrays?
Use a loop.
 

1. What is the purpose of a C program for calculating tax brackets?

A C program for calculating tax brackets is used to determine the amount of tax an individual or business owes based on their income. It takes into account the different tax rates for different income levels in order to accurately calculate the tax owed.

2. How does a C program for calculating tax brackets work?

A C program for calculating tax brackets typically follows a series of steps to determine the taxable income, apply the appropriate tax rates, and calculate the final tax amount. This is usually done using conditional statements and mathematical operations.

3. Can a C program for calculating tax brackets handle multiple income sources?

Yes, a C program for calculating tax brackets can handle multiple income sources by taking into account the total taxable income from all sources and applying the appropriate tax rates accordingly.

4. Is it necessary to have prior knowledge of tax brackets to use a C program for calculating them?

No, a C program for calculating tax brackets does not require prior knowledge of tax brackets. However, it may be helpful to have a general understanding of how tax brackets work in order to better understand the program's output.

5. Are there any limitations to using a C program for calculating tax brackets?

One potential limitation of using a C program for calculating tax brackets is that it may not account for all possible deductions or credits that could affect an individual or business's tax liability. It is important to consult with a tax professional for a comprehensive understanding of one's tax situation.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
929
  • Engineering and Comp Sci Homework Help
Replies
3
Views
889
  • Engineering and Comp Sci Homework Help
Replies
3
Views
670
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
3K
Back
Top