Answer:
#include <iostream>
using namespace std;
int main()
{
const int NUM_ROWS = 2;
const int NUM_COLS = 2;
int milesTracker[NUM_ROWS][NUM_COLS];
int i = 0;
int j = 0;
int maxMiles = -99; // Assign with first element in milesTracker before loop
int minMiles = -99; // Assign with first element in milesTracker before loop
milesTracker[0][0] = -10;
milesTracker[0][1] = 20;
milesTracker[1][0] = 30;
milesTracker[1][1] = 40;
maxMiles = milesTracker[0][0];
minMiles = milesTracker[0][0];
for (i = 0; i < NUM_ROWS; i++){
for (j = 0; j < NUM_COLS; j++){
if (milesTracker[i][j] > maxMiles){
maxMiles = milesTracker[i][j];
}
if (milesTracker[i][j] < minMiles){
minMiles = milesTracker[i][j];
}
}
}
cout << "Min: " << minMiles << endl;
cout << "Max: " << maxMiles << endl;
return 0;
}
Explanation:
It seems you want to find the min and max value in the array. Let me go through what I added to your code.
Set the maxMiles and minMiles as the first element in milesTracker
Create a nested for loop that iterates through the milesTracker. Inside the loop, check if an element is greater than maxMiles, set it as maxMiles. If an element is smaller than minMiles, set it as minMiles.
When the loop is done, print the minMiles and maxMiles