// sumLoopEOFArray.cc  P.Conrad for CISC181 Spring 2007
// Read integers from stdin, one per line, ending with EOF (end of file)
// Output the sum (with no special labels---just a bare number)

// instead of using cin to read, we'll read an entire line of text,
// then use atoi to get the first integer on the line.

// If a line does not contain numeric data as the first thing on the line,
// the result will be that that line will be recorded as a zero.

// If we are just interested in computing a sum, that might be fine.
// If we are finding an average, or a min or a max, or something else,
// that could be a problem.


#include <iostream>
using namespace std;

void  printArray(int array[],int size)
{
  for ( int i=0; i<size;  i++ )
    {
      cout << array[i] << " ";
    }
  cout << endl;  
}

int main()
{
  // initialize sum and declare variable to hold the input

  int thisNum;

  const int MAXSIZE = 100;
  int nums[MAXSIZE]; // an array that can store up to 100 nums
  int count = 0;

  // read all data into my array

  const int BUFSIZE = 1024;  // probably won't get a line bigger than that
  char buffer[BUFSIZE]; // read in an entire line of text   

  cin.getline(buffer,BUFSIZE);

  while ( !cin.eof() ) // eof() is a "member function" for the object cin
    {
      thisNum = atoi(buffer); // ASCII to integer 
      
      nums[count] = thisNum;
      count ++; // increment AFTERWARDS... why?  @@@ We'll say on thursday...

      cin.getline(buffer,BUFSIZE);
    }
  
  // see if it worked

  printArray(nums,count);

  return 0;
}




