Program 15.17 from chapter 15