Function for programming assignment 2