Problem 6

Added a condition to the code.