There are functions specifically for what you're doing in lines 53 & 54. Look up the MIN() and MAX() functions. Lines 53 & 54 can be reduced to the following. CY=MIN(MAX(CY,8),12)