{Urgent} Find row/column of array element in last iteration of for loop?

So I wrote a program to find the min and max value from a set of input data[i][j]. The problem is I need to know what row and column they are in, but I only am given the actual value which is determined at the last iteration of the loop. I've been looking online to find a way to identify the very last set of values for [i][j] at the end of the for loop or just a way of identifying the row/column when you just know the value from the data set. I would really appreciate any help with this.

I'm trying to find the row/column values for mn and mx in the code below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

int main()
{
	double data[25][41];
	std::ifstream file("C:\\Ergebnis_Knotendruck.csv");

	for (int row = 0; row < 25; ++row)
	{
		std::string line;
		std::getline(file, line);
		if (!file.good())
			break;

		std::stringstream iss(line);

		for (int col = 0; col < 41; ++col)
		{
			std::string val;
			std::getline(iss, val, ';');
			if (!iss.good())
				break;

			std::stringstream convertor(val);
			convertor >> data[row][col];
		}
	}

	int pmin = 25;
	int pmax = 45;
	double mndiff, mxdiff;
	double mn, mx;
	

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

		for (int j = 1; j < 41; j++)
		{

			mn = data[1][1];
			mx = data[1][1];
		}
	}
	for (int i = 2; i < 25; i++)
	for (int j = 1; j < 41; j++)
	{
		if (mn>data[i][j])
		{
			mn = data[i][j];
		}
		else if (mx<data[i][j])
		{
			mx = data[i][j];
		}
		
	}

	if (mn < pmin)
	{
		mndiff = pmin - mn;
	}
	else mndiff = 0;
	
	if (mx > pmax)
	{
		mxdiff = mx - pmax;

	}
	else mxdiff = 0;

	cout << data[1][1] << endl;
	cout << "Max pressure is: " << mx << endl;
	cout << "Min pressure is: " << mn << endl;
	cout << "Max pressure is over constraint by: " << mxdiff << endl;
	cout << "Min pressure is under constraint by: " << mndiff << endl;
	
	cin.get();
	return 0;
}
Last edited on
Make copies of i and j (in, jn, ix, jx) whenever you update the mn and mx. Then you have the "winning" indices stored.
Topic archived. No new replies allowed.