# Thread: Finding Max and Min Value

1. ## Finding Max and Min Value

Hi,
The problem is that I have a program which processes a 2D array. One task is to find the min and max of one column (ignoring the second). Here is my code so far:
Code:
```#include <iostream.h>
#include <stdlib.h>
#include <fstream>

using namespace std;

double data[4][2]; // declare 2D array for data in file.
int count;
int counter=0;
int numberOfSpeedIntervals;
int numberOfSectors;

int main()
{
ifstream inPutFile;//Creates stream to input file.

if (!inPutFile)//Deals with problems opening file.
cout << "Error opening file!" << endl;

//Finds how many lines of data there are.
int item;
while (!inPutFile.eof())
{
inPutFile >> item;
counter++;
}
const int rows = (counter/2);
cout<<"Number of rows: "<<rows<<endl;

cout<<"Please type how many intervals do you require: ";
cin>> numberOfSpeedIntervals;

cout<<"Please type how many sectors do you require: ";
cin>> numberOfSectors;

//initialise current max and min
// find max and min
// initialise current max and min

for (int i = 1; i < data; i++)
{

{
}

{
}

}

system("PAUSE");
return 0;
}```
The last lines are faulty. Any ideas?

Will

2. for (int i = 1; i < data; i++)
the limit is incorrect - should be 4 (best declare it as const somewhere and use in every place in the code you need the array size)

3. Thanks,
I changed data to rows which is the user set variable set by user. Code now reads:
Code:
```.
.
.
.
while (!inPutFile.eof())
{
inPutFile >> item;
counter++;
}
const int rows = (counter/2);
cout<<"Number of rows: "<<rows<<endl;
.
.
.
.
//initialise current max and min
// find max and min
// initialise current max and min

for (int i = 1; i < rows; i++)
{

{
}

{
}