FORTRAN: Problem with converting reals to integers

  • Comp Sci
  • Thread starter mattmac.nuke
  • Start date
  • #1

Homework Statement


I'm trying to convert data that's entered as a real number into integer data to be used in a do loop. The problem is that it keeps telling me that the numbers I've just converted are not scalar integers...


The Attempt at a Solution



program interest
IMPLICIT NONE
REAL :: r !Monthly interest rate
REAL :: pay !Montyly Payment Amount
REAL :: p !Initial loan amount (Money borrowed)
INTEGER :: n, i, j !Total number of payments to be made
REAL :: i_max !Maximum Interest rate
REAL :: i_min !Minimum Interest rate
REAL :: t_max !Maximum amount of Time for Loan payback
CHARACTER :: x



WRITE (*,*) 'COP 2271- Project 2'
WRITE (*,*) ' Interest rates '
WRITE (*,*) '-------------------------'
WRITE (*,*) 'Main Menu'
WRITE (*,*) ' A) Enter new Data'
WRITE (*,*) ' Q) Quit'
READ (*,*) x

DO
SELECT CASE (x)
CASE ('A','a')
DO
WRITE (*,*) 'Enter principle loan amount($)'
READ (*,*) p
WRITE (*,*) 'Enter maximum length of the loan(Years):'
READ (*,*) t_max
WRITE (*,*) 'Enter minimum interest rate(%):'
READ (*,*) i_min
WRITE (*,*) 'Enter maximum interest rate(%):'
READ (*,*) i_max
END DO
CASE ('Q','q')
EXIT
CASE DEFAULT
WRITE (*,*) 'Invalid Selection'
END SELECT

IF (p < 0) WRITE (*,*) 'ERROR- Principle amount must be positive!'
IF (t_max < 3) WRITE (*,*) 'ERROR- Maximum loan length must be greater than or equal to 3 (years)!'
IF (i_min < 0 .OR. i_min > 100 .OR. i_min > i_max) WRITE (*,*) 'Error- Interest rate must be between 0 and 100!'
IF (i_max < 0 .OR. i_max > 100) WRITE (*,*) 'Error- Interest rate must be between 0 and 100!'

END DO

i_max = CEILING(i_max)
i_min = INT(i_min)
t_max = CEILING(t_max)

DO i = 2, t_max
n = 12*i
pay = (r*p)/(1-((1 + r)**(-n)))

DO j = i_min, i_max

WRITE (*,'(3X,I3,8X,I3,5X,A,F10.2, 5X,A, F10.2)')


END DO
END DO


end program interest


-This is the program as I've written it so far, it's not finished... I'm also having problems with the formatting they want us to use for the tables.
 

Answers and Replies

  • #2
SteamKing
Staff Emeritus
Science Advisor
Homework Helper
12,796
1,668
I don't think you can declare i_min as a REAL and then expect the type to convert to INTEGER after executing the statement: i_min = INT (i_min). You should assign the converted value of i_min to another variable of TYPE INTEGER.
 

Related Threads on FORTRAN: Problem with converting reals to integers

Replies
2
Views
3K
Replies
3
Views
4K
Replies
1
Views
2K
  • Last Post
Replies
5
Views
583
  • Last Post
Replies
6
Views
2K
Replies
4
Views
606
Replies
18
Views
1K
  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
7
Views
826
Top