/*****************************************************************************************
   Author  : Yan Huang
   Date    : 02.18.07
   Synopsis: to show how to get a list of numbers and store them in a list and then output
             their summation
******************************************************************************************/

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

/* read an integer from standard input */
int readNumber(int &i){
   char c;

   c = cin.get();
   if ( c<= '9' && c >= '0')
       cin.unget();
   else if (c == '\n') return 0;
   cin >> i;
   return 1;
}

main()
{
   list<int> L;
   int number, sum=0;

   cout << "Please enter a list of integers: ";
   while (readNumber(number)){
        L.push_back(number);              // Insert a new element at the end
   }


   list<int>::iterator i;

   cout << "You have entered: "; 
   for(i=L.begin(); i != L.end(); ++i){
        sum += *i;
        cout << *i << " ";
   }
   cout << endl << "The summation of the input numbers is " << sum << endl;

   return 0;
}




