C++: Two-dimensional array, how to find the row with largest difference in their columns? -
i have 2 dimensional array variable number of rows , 2 columns, supposed find row has biggest difference in columns. make more clear: given lowest , highest temperature n days , supposed find day difference between temperatures largest (and if 2 days have same difference, supposed give first one). however, have never used multidimensional arrays, not sure whether can this: a[i][1]-a[i][0]? (a[i] index of day, , a[1] highest temperature day, a[0] lowest)
this part of code looks this:
int difference (int n, float a[maxn][2]) { float difference=a[0][1]-a[0][0]; int index=0; (int i=0; i<n; i++) { if (a[i][1]-a[i][0]>difference) { index=i; a[i][1]-a[i][0]=difference; //here error message: lvalue required left operand of assignment } } return index+1; //to day largest difference if don't assignment, make value equal difference ==, says "statement has no effect", thinking maybe not allowed trying do.
- you're shadowing function's name - might want 1 of
differenceelse. =works variable you're trying assign on left. try:difference = a[i][1] - a[i][0];
Comments
Post a Comment