Hello guys,
I'm trying to read a minimum value from a file, but the file contain two minimum values that are the same. Here's a example
file
32 345 23 122
21 23 233 239
132 252 21 231
673 141 45 211
How could I specify that the minimum value is located at column 1 and the other is located in column 3
This is what I have so far
Code:
double power [NROWS] [NCOLS], min;
string Days[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int weeks [10] = { 1,2,3,4,5,6,7,8,9,10};
int set_day, set_week;
cout << "--[ Minimum Daily Power Output] --" << endl;
ifstream inFile;
inFile.open("power1.dat");
if (inFile.fail())
{
cout << "Error opening The file " << endl;
}
else
{
for ( int i = 0 ; i <= NROWS -1; i++)
{
for ( int j = 0; j <= NCOLS-1; j++)
{
inFile >> power [i] [j];
}
}
}
for (int i=0; i<=NROWS -1; i++)
{
for ( int j = 0; j <=NCOLS -1 ; j++)
{
if ( i == 0 && j == 0)
min = power[i][j];
else
{
if ( power[i][j] <= min )
{
min = power[i][j];
set_day = j;
set_week = i;
}
}
}
}
cout << "\n\n Minimum Output is = " << min <<" megawatts" << endl;
cout << " Occurred on = " << Days[set_day] << " of week "<< weeks[set_week]<< endl;
system("pause");