Program 15.18 from chapter 15