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

int main() {
  ifstream inputFile;
  string filename;
  int number;
  long total = 0;

  // Get the filename from the user
  cout << "Please enter the filename: ";
  cin >> filename;

  // Open the file the user specified
  inputFile.open(filename);

  // vs. opening a hard-coded path:
  // inputFile.open("test.txt");

  // If the file successfully opened, process it.
  if(inputFile){
    // Read the numbers from the file and display them.
    while (inputFile >> number){
      cout << number << endl;
      total += number;
      cout << "Current total is: " << total << endl;
    }
    // Close the file.
    inputFile.close();
  }else{
    // Display an error message.
    cout << "Error opening " << filename << ".\n";
  }
  cout << "The total is: " << total << endl;
  return 0;
}