Finding maximum and minimum values in array

Hi everyone, i got a problem in finding a minimum values in array. I had search throughout the forum about this and have try it, but still not got the right answer for minimum value. I got the right answer for maximum value (155.601) but minimum display -9.25596e+061. I don't know where is the mistake i made in the coded. Hoping for help from anyone. Thanks.

input file as below in (.txt):

1 153.176
2 152.146
3 155.601
4 150.824
5 126.644

[code]

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
int i;
const int Initial_Population = 5;
int startNode [Initial_Population];
double objFunction [Initial_Population];

ifstream inputFile;

inputFile.open ("myFile.txt");

for (i = 0; i < 5; i++)
{
inputFile >> startNode[i];
inputFile >> objFunction[i];
}

inputFile.close();

double max = objFunction [Initial_Population];
double min = objFunction [Initial_Population];

for (int i = 0; i < 5; i++)
{
if (objFunction[i] > max)
{
max = objFunction[i];
}
else if (objFunction[i] < min)
{
min = objFunction[i];
}
}

cout << "The maximum obj function is: " << max << endl;
cout << "The minimum obj function is: " << min << endl;

system("pause");

return 0;

}
Initial_Population here:
1
2
double max = objFunction [Initial_Population];
double min = objFunction [Initial_Population];
is out of bounds. It is not predictable what min/max contains. So use 0 instead of Initial_Population.
Okay. I got it. Thanks for your help.
Topic archived. No new replies allowed.