restricted user intput

modified the code to check erroneous inputs from the user