| PROGRAM compute_change
INTEGER :: change, price, amount, np, n50, n20, n10, n5, n2, n1
WRITE(UNIT=*, FMT=*) 'Type in price...'
READ(UNIT=*, FMT=*) price
WRITE(UNIT=*, FMT=*) 'Type in amount handed over...'
READ(UNIT=*, FMT=*) amount
change = amount - price
CALL calc_change(change, np, n50, n20, n10, n5, n2, n1)
WRITE(UNIT=*, FMT=*) 'Change = ', np, ' pounds', &
n50, ' 50s,', n20, ' 20s,', &
n10, ' 10s,', n5, ' 5s,', &
n2, ' 2s,', n1, ' 1s.'
END PROGRAM compute_change
! -- subprogram to compute coins needed:
SUBROUTINE calc_change(change, np, n50, n20, n10, n5, n2, n1)
INTEGER, INTENT(IN) :: change ! -- INput
INTEGER, INTENT(OUT) :: np, n50, n20, n10, n5, n2, n1 ! -- OUT going
INTEGER :: remainder
remainder = change
np = remainder/100
n50 = remainder/50
...
END SUBROUTINE
|