Re-write of code for programming assignment2

initial attempt at two functions for rprog-008