Fortran 90 help

user1
03-18-2010, 06:48 PM
Hi

I need help on this code. Below is the specification of the program that I need to code.

Specification:

A building society decides to pay a bonus dependent upon the current balance of its saving accounts. There are currently 15 accounts with the following amount kept in them.

28763, 2845, 12567, 536, 59642
12658, 124632 , 4263, 61245, 563145,
7529, 15243, 452168, 12487,39487.

Each account will receive the following bonus payment for being within the specified ranges

0 - 5000 3%
5001 - 100k 5%
100k - 500k 7%
500k + 10%

You task is to create an array to hold the current balance, the percentage to be applied to a bonus, the bonus amount and the new balance including the bonus. The resultant array needs to be printed in an appropriate format

My attempt at the problem so far:
ry_calc
IMPLICIT NONE
INTEGER, DIMENSION(15) :: salary
REAL, DIMENSION(4) :: percentage
INTEGER, DIMENSION(15) :: new_salary
INTEGER, DIMENSION(15) :: bonus
INTEGER :: i=1

percentage = (/0.03,0.05,0.07,0.10/)
salary = (/28763,2845,12567,536,59642,12658,124632,4263,61245 ,563145,7529,15243,452168,12487,39487/)

DO i=1,15
IF ((salary(i)=>0) .AND. (salary(i)<=5000))THEN
bonus(i) = salary(i)*percentage(1)

ELSEIF ((salary(i)=>5001) .AND. (salary(i)<=100000))THEN
bonus(i) = salary(i)*percentage(2)

ELSEIF ((salary(i)=>100001) .AND. (salary(i)<=500000))THEN
bonus(i) = salary(i)*percentage(3)

ELSE
bonus(i) = salary(i)*percentage(4)
END IF
i = i + 1
END DO

!sumsal = SUM(salaries * increment(category))
PRINT '(5I8)', salary!'Cost of increase = ', sumsal
PRINT *
PRINT '(F7.2)', percentage
PRINT *
PRINT '(I8)', bonus

END PROGRAM salary_calc

any help would appreciated.

Thank you

User1.

michielm
03-19-2010, 06:25 AM
Your code is reasonably close to a working code, but you've forgotten some basic things:

1) the arrays in your loop should have an index:salary(i), bonus(i)
2) the loop should be defined as: Do i=1,15 or like you have it now, but then you need to manually increase i every loop
3) the print commands you give are for integers, while you have declared your arrays as real (which is not necessary by the way), so either change your declaration, or change your print statement

user1
03-19-2010, 02:49 PM
okay, I modified the above code of mine but I get errors that I don't understant what it means.

Salaries.F90(15) : error 422 - The left hand side of the pointer assignment does not have the POINTER attribute
Salaries.F90(15) : error 422 - The right hand side of the pointer assignment does not have the POINTER or TARGET attribute
Salaries.F90(15) : error 168 - INTEGER(KIND=3) expressions cannot be in logical expressions (with '.AND.')
Salaries.F90(18) : error 422 - The left hand side of the pointer assignment does not have the POINTER attribute
Salaries.F90(18) : error 422 - The right hand side of the pointer assignment does not have the POINTER or TARGET attribute
Salaries.F90(18) : error 168 - INTEGER(KIND=3) expressions cannot be in logical expressions (with '.AND.')
Salaries.F90(21) : error 422 - The left hand side of the pointer assignment does not have the POINTER attribute
Salaries.F90(21) : error 422 - The right hand side of the pointer assignment does not have the POINTER or TARGET attribute
Salaries.F90(21) : error 168 - INTEGER(KIND=3) expressions cannot be in logical expressions (with '.AND.')
Salaries.F90(27) : error 230 - I is currently being used as a DO or implied DO control variable

michielm
03-21-2010, 10:01 AM
The => and <= arguments that you use are pointer arguments, you should use .ge. (greater than or equal to) and .le. (less than or equal to). That will get you rid of all errors except the last one. That one is because you must have misunderstood my second comment: you should change your do loop into Do=1,15 OR include a i=i+1 line in the loop. Now you did BOTH and that doesn't work. So removing i=i+1 will get you rid of the last error

user1
03-22-2010, 06:53 AM
It works now, Thank you michielm. :)

michielm
03-22-2010, 07:09 AM
you're welcome