/*
 * Suppose you have the following data files:
 * -rw-r--r-- 1 solomon sys 10 May  6 21:23 a1.txt
 * ---------- 1 solomon sys 10 May  6 21:24 a2.txt
 * -rw-r--r-- 1 solomon sys 10 May  6 21:24 a3.txt
 * -rw-r--r-- 1 solomon sys 10 May  6 21:24 a5.txt
 * The output for a2.txt and a4.txt will both be 0.
 */
#include <iostream>
#include <stdio.h>
#include <fstream>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std::ios;

int main()
{
    char fn[20];
    int sum, n;
    for (int i=1; i<=5; i++)
    {
        sprintf(fn, "a%d.txt", i);
        ifstream infile(fn, ios::in);
        if (!infile) {
            cerr << fn << " cannot be opened\n";
            continue;
        }

        sum = 0;
        while (infile >> n)
            sum += n;
        cout << fn << " : " << sum << endl;
        infile.close();
    }

    return 0;
}
