|Well, this is sure messy.
Apart from anything else, all these function calls are going to slow your code down. avg works on a reference, it doesn't return a value ?
yp and xp are zero at the start of the first loop, every other time they start at -1. I'm sure that's not the only issue, but it's an indication of the sort of problems you probably have.
Please read this
if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )