I am having a problem with a program. I have the code below. It keeps producing the same number from the files when it needs to take the numbers and put them in order in the outfile.

#include <iostream>
#include <fstream> //needed library for I/O streams
using namespace std;

ifstream in_file1;
ifstream in_file2;
ofstream out_file; //tells computer to create a new file

int main()
int a, b;
//stores the two saved files to the assigned code name ("intList01.txt"); ("intList02.txt");
//creates the new output file ("outfile.txt");
//do while loop to continue through the files until they are both at end of file (.eof)
//stores the numbers into the separate integers
in_file1 >> a;
in_file2 >> b;
if (a < b)
out_file << a << endl;
out_file << b << endl;
} while (!in_file1.eof() && !in_file2.eof());

//closes the files
in_file1.close ();
in_file2.close ();
out_file.close ();
Currently, you only apply the bubble sort algorithm for one iteration and you only write one of the two numbers.
Last edited on
Topic archived. No new replies allowed.