// Mr. Minich
// CMPSC 201
// Ch. 11 Demo Program #8
// November 4, 2003
// Purpose - searching an array for the maximum element as well as
//           its position within the array

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
   int max = 0;       // maximum value of the array
   int position = -1; // position of largest element
   int array[10];     // array of values
   int i = 0;         // loop variable
   ifstream infile;   // file with data to be read

   infile.open("numbers.txt");

   for (i = 0; i <= 9; i++) // reading values from file into array
   {
      infile >> array[i];
   }

   for (i = 0; i <= 9; i++)      // cycling through each position of array
   {                             //    comparing each value to the current max

      if (array[i] > max)
      {
         max = array[i]; // replace max with new greatest value
         position = i; // marking position of new max value
      }

   }

   cout << "The greatest integer is " << max << endl;
   cout << "It was found in position " << position << endl;

   return 0;
}// end of main