The fundamentals of your program are broken anyway. No point in having input and output working if you read the data, munge it, and then write it out.
When you tell people to get in a line, in order of age, those people don't assign their ages to someone else.