Solve Fortran 90 Homework Stuck on Calculating Tax

  • Comp Sci
  • Thread starter ParisSpart
  • Start date
  • Tags
    Fortran
In summary: The IF statements would be something like this:if (income <= 9999.99 ) then tax = .05 * incomeelse if (income <= 49999.99) then tax = .05 * 10000 + .10 * (income - 10000)else if (income <= 69999.99) then tax = .05 * 10000 + .10 * 40000 + .20 * (income - 50000)else tax = .05 * 10000 + .10 * 40000 + .20 * 20000 + .25 * (income - 70000)end if
  • #1
ParisSpart
129
0

Homework Statement


The program should make should calculate the tax that corresponds to some income. The user gives

1. A natural number n is the length of the list to the bracket 2 (see next section) and one minus the length of the list percent to 3 (see the paragraph after next) and also equal to the number of rows in the table above except the line- header and the last line. In the above table the value of n is 7. We have 1 <= n <= 9.

Register as an integer :: n.

2. A list of real numbers corresponding to the first column of the table above except the heading and the last element (which can be calculated as the sum of all elements above it). The length of the list is n (the user is given) and the maximum length is 10.

Declare as real :: bracket (10).

3. A list of real numbers in [0.100] for the second column of the table above except header. The length of the list is n +1 (the n has given the user) and the maximum length is 10.

Declare as real :: percent (10).

4. Income.

Declare it as real :: income.

A model of dialogue with the user program is below. In italics are what gives the user:

How many tax brackets?

3

Tax bracket 1:

10000

Percentage for tax bracket 1:

5

Tax bracket 2:

5000

Percentage for tax bracket 2:

10

Tax bracket 3:

7000

Percentage for tax bracket 3:

20
Percentage for tax bracket 4:

25

What is your income?

26000

Your tax is 3400.0000



Homework Equations


i stucked at the point of finding the tax i don't know how to do it.Still how we can to do the part of finding the tax if income<(sum of brackets)in the dialogue of the exapmle sush as 20.000 instead of 26000.


The Attempt at a Solution



program tax
implicit none

integer :: n, i, j
real :: bracket(0:10), percent(10), income, tax, sum1, sum2, sum3, sum4

do
print *, "Give number of tax brackets (1<=n<=9)"
read *, n
if ((1<=n) .and. (n<=9)) exit
end do

do i=1,n
do
print *, "Give tax bracket No", i, ", a positive number"
read *, bracket(i)
if(bracket(i)>0) exit
end do
do
print *, "Give percentage No", i, " a number between 0 and 100"
read *, percent(i)
if((0<=percent(i)) .and. (percent(i)<=100)) exit
end do
end do
do
print *, "Give percentage No", n+1, " a number between 0 and 100"
read *, percent(n+1)
if((0<=percent(n+1)) .and. (percent(n+1)<=100)) exit
end do

do
print *, "What is your income (a positive number)?"
read *, income
if(0<=income) exit
end do


do i=1,n
sum1=sum1+bracket(i)
end do

do i=1,n
if(income>=sum1) then
sum2=sum2+(percent(i)/100)*bracket(i)
tax=sum2+(percent(n+1)/100)*(income-sum1)



print *, "Your tax is ", tax

end program
 
Physics news on Phys.org
  • #2
ParisSpart said:
i stucked at the point of finding the tax i don't know how to do it.Still how we can to do the part of finding the tax if income<(sum of brackets)in the dialogue of the exapmle sush as 20.000 instead of 26000.
Minor point: There is no such word as "stucked." What you should say is, "I got stuck."

Regarding your question about how to compute the tax, your example run makes no sense. In the sample run, the user has entered 3 for the number of brackets, but there are 4 tax rates.

Also, the first bracket is 10,000, but the second and third are 5,000 and 7,000. Should these be 50,000 and 70,000?

For the tax rates, it's not clear how they apply. Is it 5% on incomes between 0 and 9,999, 10% on incomes between 10,000 and 49,999, 20% on incomes between 50,000 and 69,999, and 25% on everything above 70,000?

When you post code, put a [noparse]
Code:
 tag at the top and a
[/noparse] tag at the bottom. I have done that for your code.
ParisSpart said:
Code:
program tax
 implicit none
 
integer :: n, i, j
 real :: bracket(0:10), percent(10), income, tax, sum1, sum2, sum3, sum4
 
do
 print *, "Give number of tax brackets (1<=n<=9)"
 read *, n
 if ((1<=n) .and. (n<=9)) exit
 end do

 do i=1,n
 do
 print *, "Give tax bracket No", i, ", a positive number"
 read *, bracket(i)
 if(bracket(i)>0) exit
 end do
 do
 print *, "Give percentage No", i, " a number between 0 and 100"
 read *, percent(i)
 if((0<=percent(i)) .and. (percent(i)<=100)) exit
 end do
 end do
 do
 print *, "Give percentage No", n+1, " a number between 0 and 100"
 read *, percent(n+1)
 if((0<=percent(n+1)) .and. (percent(n+1)<=100)) exit
 end do

 do
 print *, "What is your income (a positive number)?"
 read *, income
 if(0<=income) exit
 end do
 

do i=1,n
 sum1=sum1+bracket(i)
 end do

 do i=1,n
 if(income>=sum1) then
 sum2=sum2+(percent(i)/100)*bracket(i)
 tax=sum2+(percent(n+1)/100)*(income-sum1)

 

print *, "Your tax is ", tax
 
end program
 
  • #3
Assuming for the moment that my interpretation of the problem is correct, here is how you compute the tax.

Incomes between 0 and 9,999: tax = .05 * income
Incomes between 10,000 and 49,999: tax = .05 * 10,000 + .10 * (income - 10,000)
Incomes between 50,000 and 69,999: tax = .05 * 10,000 + .10 * 40,000 + .20 (income - 50,000)
Incomes of 70,000 and above: tax = .05 * 10,000 + .10 * 40,000 + .20 * 20,000 + .25 * (income - 70,000)

You need several IF statements to do the calculation.
 
  • #4
i think that i found how to do it but , i have a problem how to do the finally step of finding where is the position of income in the intervals here is what i think of finding the tax:Calculated after the table real :: t (0:10) the person pays the income is equal to s (i).

Finally, having calculated the table t (i) and as income for income tax to find (in the variable tax) must decide which of the intervals

[s (0), s (1)], [s (1), s (2)], [s (2), s (3)], ... , [S (n-1), s (n)], [s (n), + \ infty)

is the number of income. If your income is the starting time s (i) (with i = 0,1, ..., n) then the tax is

tax = t (i) + (income-s (i)) * percent (i +1) * 0.01

(code:)
s(0) = 0

do i=1,n
s(i) = s(i-1)+bracket(i)
end do

t(0) = 0

do i=1,n
t(i) = t(i-1)+percent(i)*0.01*bracket(i)
end do
 
  • #5
Please read what I said in post #3
Incomes between 0 and 9,999: tax = .05 * income
Incomes between 10,000 and 49,999: tax = .05 * 10,000 + .10 * (income - 10,000)
Incomes between 50,000 and 69,999: tax = .05 * 10,000 + .10 * 40,000 + .20 (income - 50,000)
Incomes of 70,000 and above: tax = .05 * 10,000 + .10 * 40,000 + .20 * 20,000 + .25 * (income - 70,000)

You need several IF statements to do the calculation.
 

Related to Solve Fortran 90 Homework Stuck on Calculating Tax

1. What is Fortran 90?

Fortran 90 is a programming language used for scientific and numerical computing. It was developed in the 1990s and is an updated version of the original Fortran programming language. It is still commonly used in scientific and engineering applications due to its high performance and efficient handling of mathematical operations.

2. How do I calculate tax using Fortran 90?

To calculate tax using Fortran 90, you will need to use the appropriate mathematical formulas and functions within the language. These will vary depending on the specific tax rates and calculations for your location or situation. It is important to consult resources specific to your needs or seek help from a programmer or tax professional.

3. Why am I stuck on calculating tax in Fortran 90?

There could be several reasons why you may be stuck on calculating tax in Fortran 90. Some possible reasons include errors in your code, incorrect use of mathematical functions, or a lack of understanding of the specific tax calculations you are trying to perform. It is important to carefully review your code and seek help if needed.

4. What are some tips for solving Fortran 90 homework related to calculating tax?

Some tips for solving Fortran 90 homework related to calculating tax include thoroughly understanding the tax calculations you need to perform, breaking down the problem into smaller steps, and regularly testing and debugging your code. It can also be helpful to seek help from a teacher, tutor, or online resources.

5. Are there any resources available to help me with Fortran 90 and calculating tax?

Yes, there are many resources available to help with Fortran 90 and calculating tax. These include online tutorials, forums, and documentation, as well as textbooks and courses. It can also be helpful to consult with a programmer or tax professional for guidance and assistance with specific calculations.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
864
  • Engineering and Comp Sci Homework Help
Replies
22
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
Back
Top