//John Paul Kruszewski
#include <cstdlib>
#include <iostream>
#include <fstream>
float average_depth(float matrix[][6], int size);
using namespace std;

int main()
{
	ifstream infile;
	ofstream outfile;
	infile.open("data.txt");
	outfile.open("results.txt");
	if(!infile)
	{
		cout <<"There was an error in the opening of the data file"<<endl;
		exit(0);
	}

	int total=0;
	float average=0, temp, actualaverage, matrix[6][6];

	for(int i=0; i<=5; i++)
	{
		for(int j=0;j<=5;j++)
		{
			infile>>temp;
			matrix[i][j]=temp;
			total=total+1;
			average=average+matrix[i][j];
		}
	}

	
	int x,y;
	float max=0;
	for(int k=0; k<=5;k++)
	{
		for(int l=0;l<=5;l++)
		{
			if(matrix[k][l]>max)
			{
				max=matrix[k][k];
				x=k;
				y=l;
			}
		}
	}

	actualaverage=average/total;
//	actualaverage=average_depth(matrix, 36);

	cout <<matrix;

	int squaremaxx, squaremaxy;				//These are the variables that will get returned 
	float depth=0,average_depth;
	for(i=0;i<=5;i++)
	{
		for(int j=0;j<=5;j++)
		{
			if(i+1<5 && j+1<5)
			{
				average_depth=(matrix[i][j]+matrix[i+1][j]+matrix[i][j+1]+matrix[i+1][j+1])/4;
					if(average_depth>depth)
					{
						depth=average_depth;
						squaremaxx=i;
						squaremaxy=j;
					}
			}
		}
	}
	
	outfile <<"The depth matrix is :"<<"/n/n";
	for(i=0;i<=5;i++)
	{
		for(int j=0;j<=5;j++)
		{
			outfile << matrix[i][j]<<"/t";
		}
		outfile <<"/n";
	}
	outfile <<"The deepest point in the ocean is " <<max<<" at "<<x<<","<<y<<endl;
	outfile <<"The average depth of the deepest square is " <<actualaverage<<" bounded by"<<squaremaxx<<","<<squaremaxy<<")"<<" and (" <<squaremaxx+1<<","<<squaremaxy<<")/n)";
	outfile <<"The average depth is " <<actualaverage <<endl;
	return 0;
}


/*float average_depth(float matrix, int size)
{
	float average;
	for(int i=0;i<=size;i++)
	{
		average=average+matrix[i];
	}
	return average;
}
*/