Having trouble on solving the following tasks

Now you have working code could you tell us why you used this method? Extra marks may be scored for pointing out the problems with this method and a better solution.

Mark