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