added a do-while loop and a count variable ‘r’ to handle if the request
made is not a valid request