title: Read from text file, do math using functions using c++
body: <p><strong>This is the formal description of what I am supposed to do:</strong></p>
  
  <p>Write a program that reads integers (whole numbers) from a text file (make your own text
  file with whole numbers on separate lines). You must output the following information
  to the screen:
  a) How many even numbers are there?
  b) How many odd numbers are there?
  c) The sum and average of all the numbers in the file.
  You must have the following functions in your program.
  • A function to open the file passing the file stream variable as a reference parameter.
  • A function to read the number from the file and pass by value to the next function
  • This function called classify, will count the even, and odd numbers and keep
  accumulating sum. Sum, evenCount, and oddCount must be passed to this function
  by reference.
  • And main to test the above functions and do the rest of the work.</p>
  
  <p>I am having a lot of trouble with this program. The code I have so far is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  
  int oFile();
  int readNum();
  int classify();
  
  int main() 
  {
      oFile();
      classify();
      int sum, evenCount, oddCount;
  
  
  
      return 0;
  }
  
  int oFile()
  {
      string inputFileName;
      ifstream inputFile;
  
      cout &lt;&lt; "Input the file name: ";
      getline(cin, inputFileName);
  
      //open file
      inputFile.open(inputFileName);
  
  
      if (!inputFile.is_open())
      {
          cout &lt;&lt; "Unable to open file" &lt;&lt; endl;
          exit(1);
      }
  
  
  }
  
  int readNum() {
  ifstream inputFile;
      int i;
      while (inputFile &gt;&gt; i) {
          cout &lt;&lt; "The value from file is: " &lt;&lt; i &lt;&lt; endl;
      }
      return 0;
  }
  
  
  int classify()
  {
  ifstream inputFile;
      int sum = 0, even = 0, odd = 0, x = 0, sumcount = 0;
      while (inputFile.peek() != EOF)
      {
          cout &lt;&lt; "Next integer in file: " &lt;&lt; x &lt;&lt; endl;
          sum = sum + x;
          sumcount++;
          if (x % 2 == 0)
              even++;
          else
              odd++;
      }
  
      return sum;
  
  }
  </code></pre>
  
  <p>When I run this program I get prompted to enter a file name, but when I enter the file name I have that is full of numbers my if statement runs and says Unable to open file. I don't know where to go from here with this program and I am very new to functions so any help would be appreciated in making progress. As you can notice I haven't even finished the program yet. My main problem is getting all the functions to run smoothly after one another, I am not sure how to call each of these functions to have the program properly run. Another problem is that I don't know how to call the file name that the user enters in the functions. I guess what I'm asking is: if someone could maybe write the skeleton code for each of the functions I need. Thank you. </p>