/*****************************************************
 Write a program that works as follows:
 - Ask the user for a filename containing integers.
 - Store the even numbers in the file in file "even.txt" 
   and the odd numbers in "odd.txt".
*****************************************************/

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  // opean the input file 
  cout << "Filename? ";
  string fname;
  cin >> fname; 
  ifstream fin(fname);

  // check if the file exists
  if(!fin)
  {
    cout << "File doesn't exist!" << endl;
    return 1;
  }

  // open the output files
  ofstream feven("even.txt");
  ofstream fodd("odd.txt");

  // read and write the data
  int n;
  while( fin >> n )
  {
    if( n % 2 == 0 )
      feven << n << " ";
    else
      fodd << n << " ";
  }

  feven << endl;
  fodd << endl;

  return 0;
}