title: C++: How to swap integers in text files?
body: <blockquote>
  <p>Write a program that will read the two input files &quot;input1.txt&quot; and
  &quot;input2.txt&quot;, which contain only integers. The program should form one
  output file &quot;output.txt&quot;. The program should combine both input files
  into one output file. The program should compare the numbers read from
  both files. Write a smaller number in the first column and a larger
  number in the second. In the third column, write in which file there
  was a smaller number. If they were the same, write &quot;same&quot; in the third
  column.</p>
  </blockquote>
  <p>I'm having problems with this program, because first of all I'm a beginner and I'm still learning.
  Here is my code so far, it's not complete but I don't know what to do next.</p>
  <pre><code>int number1, number2, counter1 = 0, counter2 = 0, pom = 0;
  ifstream input1;
  ifstream input2;
  ofstream output;
  while (input1 &gt;&gt; number1) {
      counter1++;
      output &lt;&lt; number1 &lt;&lt; &quot; &quot;;
  }
  while (input2 &gt;&gt; number2) {
      counter2++;
      output &lt;&lt; number2 &lt;&lt; &quot; &quot;;
  }
  if (counter1 &gt; counter2)
      pom = number1;
  for (int i = 0; i &lt; counter1; i++) {
      input1 &gt;&gt; number1;
      input2 &gt;&gt; number2;
      if (number1 &lt; number2)
      {
          output &lt;&lt; number1 &lt;&lt; number2;
          output &lt;&lt; &quot;First&quot; &lt;&lt; &quot;\n&quot;;
      }
      else if (number1 &gt; number2)
      {
          number1 = number2;
          number2 = pom;
          output &lt;&lt; number1 &lt;&lt; number2;
          output &lt;&lt; &quot;Second&quot; &lt;&lt; &quot;\n&quot;;
      }
      else
      {
          output &lt;&lt; number1 &lt;&lt; number2;
          output &lt;&lt; &quot;Same&quot; &lt;&lt; &quot;\n&quot;;
      }
          
  }
  
  
  input1.close();
  input2.close();
  output.close();
  return 0;
  </code></pre>