PROGRAM Acid_Dilution
!-----------------------------------------------------------------------
! Program to determine how often a mixture of acid and water can be
! used before its acidity falls below some specified lower limit, and
! to determine the acidity of the diluted mixture after a given number
! of castings have been immersed in it   Variables used are:
!   Acidity          : amount of acid in the mixture
!   Water            : amount of water added with each casting immersion
!   Limit_on_Acidity : lower limit on acidity
!   MaxCastings      : maximum number of castings that can be cleaned
!   NumCastings      : number of castings to be cleaned
!   Concentration    : proportion of acid in the mixture
!  
! Input:   Acidity, Water, Limit_on_Acidity, NumCastings
! Output:  MaxCastings, Concentration
!------------------------------------------------------------------------

  IMPLICIT NONE
  INTEGER :: MaxCastings, NumCastings
  REAL :: Acidity, Water, Limit_on_Acidity, Concentration

  ! Enter original amount of acid, amount of water transferred,
  ! and lower limit on acidity

  PRINT *, "Enter original amount of acid (gal), amount of water added (gal),"
  PRINT *, "and the lower limit on the acidity:"
  READ *, Acidity, Water, Limit_on_Acidity

  ! Calculate and display the maximum number of castings that can
  ! be cleaned

  MaxCastings = 1 + INT(LOG(Limit_on_Acidity) / &
               (LOG(Acidity) - LOG(Acidity + Water)))
  PRINT *, "At most", MaxCastings, "castings can be immersed before "
  PRINT *, "acidity falls below", Limit_on_Acidity

  ! Enter number of castings to be cleaned

  PRINT *
  PRINT *, "How many castings are to be cleaned (at most", MaxCastings, ")?"
  READ *, NumCastings

  ! Calculate and display the acidity after this many castings have
  ! been immersed

  Concentration = (Acidity / (Acidity + Water)) ** NumCastings
  PRINT *, "The proportion of acid in the mixture after"
  PRINT *, NumCastings, "immersions is", Concentration

END PROGRAM Acid_Dilution
