#include <iostream.h>
#include <strstream.h>
#include <string>

// illustrates use of string streams
// Owen Astrachan, 1/25/96

int main()
{
    string s;
    cout << "program computes averages of lines of numbers."  << endl;
    cout << "to exit, use end-of-file" << endl << endl;

    while (getline(cin,s))
    {
        istrstream input( s.c_str() );		// convert string to c_string
        int total = 0;
        int count = 0;
        int num;
        while ( input >> num )				// "input" = input string stream
        {
            count++;
            total += num;
        }
        if (count != 0)
        {
            cout << "average of " << count << " numbers = "
                << double(total)/count << endl;     
        }
        else
        {
            cout << "data not parsed as integers" << endl;
        }
    }
    return 0;
}

