/***************************************************
Average and Maximum

Write a program that reads in positive integers from 
the user, each separated by a space, and the whole 
terminated by a negative number (e.g. 3 22 10 -2),
and returns the average and mximum of the numbers entered (not
including the terminated negative number!).  

Note: The average might not be an integer!
***************************************************/
#include <iostream>
using namespace std;

int main()
{
  // initialization
  cout << "Enter numbers separated by spaces"
       << " and terminated with a negative number."
       << endl;
  int sum, k, num, max;
  sum = 0;
  num = 0;

  // read the first number
  cin >> k;

  // initialize max: maximum so far is the first number 
  max = k;    

  // Loop while the user enters more data
  while (k >= 0)
  {
    // update the sum and num
    sum = sum + k;
    num = num + 1;

    // check whether k is the biggest so far
    if( k > max )
      max = k;

    // read the next value
    cin >> k;
  }

  // write out result
  cout << "The average is " << sum / double(num) << endl;
  cout << "The maximum is " << max  << endl;

 return 0;
}