I did it that way in case, in the future, someone wanted to change the display to 6 per line, all they'd have to do is change every instance of 5 to 6.
This sounds like a good place to use a constant.
Code:
const int ITEMS_PER_LINE = 5;
[...]
for(numbers = 0; numbers < maxlist; numbers++)
{
infile>>list[numbers];
if((numbers + 1) % ITEMS_PER_LINE == 0)
{
outfile<<list[numbers]<<" "<<endl;
cout<<list[numbers]<<" "<<endl;
}
else
{
outfile<<list[numbers]<<" ";
cout<<list[numbers]<<" ";
}
}
Now if you want to change the display to 6 per line, you only have to make one change, regardless of how many times you write the display loop.