Program 16.2 from chapter 16