finished code for quiz3 in chapter8