/***************************************
* Read in a file of the following form:
* the file begins with a number n, and
* then has n lines, each containing one
* number. Your goal is to keep a running
* sum where the first number is added, the
* second subtracted, the third added, the
* fourth subtracted, and so on. The file's
* name is input by the user.
***************************************/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// Get file name
string fname;
cout << "Filename: ";
cin >> fname;
// Open file & read n - we really should check that the file was found!
ifstream fin(fname);
int n;
fin >> n;
// read and sum values
int sum = 0, next;
for(int i = 0; i < n; i++)
{
fin >> next;
if ( i % 2 == 0 )
sum += next;
else
sum -= next;
}
// print result
cout << sum << endl;
return 0;
}