the formula for finding the total spent has been added with a comment.