declared the three variables outside the FOR loop instead of inside the FOR loop