Hello everyone ,

This function is supposed to merge 2 input files both contain sorted integers from the smallest to the largest into an output file which must be sorted too … everything works fineexceptwhen I have the same number in both input files i have it written twice in the out put file and this is wrong ...I tried to solve this problem but I couldn't… any ideas????!

Code:void merge ( ifstream& infile_1 , ifstream& infile_2 , ofstream&outfile ) { int number_1 , number_2 ; infile_1 >> number_1 ; infile_2 >> number_2 ; 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 ; } // ====================================// if ( number_1 == number_2) { outfile << number_1 << endl ; infile_1 >> number_1 ; } } // ****************************************// while (!infile_1.eof()) // while there are still numbers in the first input file... { outfile << number_1 << endl ; infile_1 >> number_1 ; } while (!infile_2.eof()) // while there are still numbers in the second input file... { outfile << number_2 << endl ; infile_2 >> number_2 ; } }