Exercise from the end of Chapter 7 of Learn to Program by Chris Pine