Program 16.5 from chapter 16