example 5-2: handle bad terminal input