"i" runs from 0 to 4 but "add_homeing" array size is 3 only. On the other hand the calculated value gets overwritten by either one of the if choice.