Program 15.12 from chapter 15