Error on exiting while() loop when input = exit