/****************************************************
Write a program that reads in the file numbers.txt
and prints out the min and the max of the numbers
there - for the moment let's force ourselves to
do the min/max computation *after* we've read in the
whole file. The file numbers .txt looks like this:
N = 3
DATA:
67
61
82
I.e. there's a header that tells you how many numbers
are in the file, and then you get all the numbers.
****************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// Open input file, read header, get N = # of int's
ifstream IN("numbers.txt");
char c;
int N;
string s;
IN >> c >> c >> N >> s;
// Create array A and read N int's from input
int *A = new int[N];
for(int i = 0; i < N; i++)
IN >> A[i];
// Cycle through array keeping min & max values
int min, max;
min = max = A[0];
for(int j = 1; j < N; j++)
{
if (A[j] > max)
max = A[j];
else if (A[j] < min)
min = A[j];
}
// Print out the min and the max
cout << "The minimum value is " << min << endl;
cout << "The maximum value is " << max << endl;
return 0;
}