I have a two dimensional array with a variable number of rows and two columns, I am supposed to find the row that has the biggest difference in its columns. To make it more clear: I am given the lowest and highest temperature for n days and I am supposed to find the day where the difference between the temperatures is the largest (and if two days have this same difference, then I am supposed to give only the first one). However, I have never used multidimensional arrays, so I am not sure whether I can do something like this: a[i][1]-a[i][0]? (a[i] is the index of the day, and a[1] is the highest temperature for the day, a[0] is the lowest)
This part of my code looks like this:
int difference (int n, float a[maxn][2]) {
float difference=a[0][1]-a[0][0];
int index=0;
for (int i=0; i<n; i++) {
if (a[i][1]-a[i][0]>difference) {
index=i;
a[i][1]-a[i][0]=difference; //HERE I get the error message: lvalue required as left operand of assignment
}
}
return index+1; //to get the day with the largest difference
If I don’t do it as an assignment, but I make the value equal to difference with ==, then it says that “statement has no effect”, so I was thinking that maybe I am not allowed to do what I am trying to do.
differenceto be something else.=only works with the variable you’re trying to assign to on the left. Try: