Formatted problem #6 code