revised prob2.cpp