attempted solution for programming assignment 2