new changes and added purge() after each scanf()