I'm supposed to write a program that merges the numbers in two files and writes all the numbers into a third file. The program takes input from two different files and writes its output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to the largest. After the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. I'm not 100% sure my logic is correct. Thank you for your help.
inputFile1:
1 2 3 4 5 6 7 8 9 10
inputFile2:
11 12 13 14 15 16 17 18 19 20
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;
int main()
{
int num1, num2;
ifstream inputFile;
ifstream inputFile2;
inputFile.open ("input1.txt");
inputFile2.open("input2.txt");
ofstream outputFile;
outputFile.open("output.txt");
inputFile >> num1;
inputFile2 >> num2;
while(inputFile.eof() && inputFile2.eof())
{
if (num1 < num2)
{
outputFile << num1;
inputFile >> num1;
}
else
{
outputFile << num2;
inputFile2 >> num2;
}
}
inputFile.close();
inputFile2.close();
outputFile.close();
return 0;
}