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: Problem with converting reals to integers

  1. Sep 20, 2011 #1
    1. The problem statement, all variables and given/known data
    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...


    3. 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.
     
  2. jcsd
  3. Sep 20, 2011 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: FORTRAN: Problem with converting reals to integers
Loading...