Try this (I added in comments where i changed it)
Code:
...
while ( (!infile_1.eof()) &&(!infile_2.eof()) )
// while not end of file for both input files...
{
if ( number_1 > number_2)
{
outfile << number_2 << endl ;
infile_2 >> number_2 ;
}
// ====================================//
else if ( number_1 < number_2)
{
outfile << number_1 << endl ;
infile_1 >> number_1 ;
}
// ====================================//
else if ( number_1 == number_2) // Yes, this should be an else. If one of the above matches, then this could trigger also, which would produce errors. You only want one of these three to trigger
{
outfile << number_1 << endl ;
infile_1 >> number_1 ;
infile_2 >> number_2 ; // You need to get rid of BOTH numbers, because they are equal, and you only want one of them.
}
...