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!

FOrtran 90 stucked

  1. Mar 5, 2012 #1
    1. The problem statement, all variables and given/known data
    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



    2. Relevant equations
    i stucked at the point of finding the tax i dont 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.


    3. 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
     
  2. jcsd
  3. Mar 5, 2012 #2

    Mark44

    Staff: Mentor

    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 (Text):
     tag at the top and a
    [/noparse] tag at the bottom. I have done that for your code.
     
  4. Mar 5, 2012 #3

    Mark44

    Staff: Mentor

    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.
     
  5. Mar 6, 2012 #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
     
  6. Mar 6, 2012 #5

    Mark44

    Staff: Mentor

    Please read what I said in post #3
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: FOrtran 90 stucked
  1. Fortran 90 Question (Replies: 1)

  2. Fortran 90 (Replies: 1)

Loading...