finished prob2.cpp