Ask Question
13 October, 12:42

Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program:Min miles: - 10Max miles: 40#include 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; / * Your solution goes here * / cout << "Min miles: " << minMiles << endl; cout << "Max miles: " << maxMiles << endl; }

+2
Answers (1)
  1. 13 October, 13:35
    0
    Following are th program in the C+ + Programming Language.

    #include / /set Header files

    using namespace std; //set namespace

    //define main function

    int main ()

    {

    //set integer constants variable

    const int NUM_ROWS = 2;

    //set integer constants variable

    const int NUM_COLS = 2;

    //set integer type array

    int milesTracker[NUM_ROWS][NUM_COLS];

    //set integer type variable and initialize to 0

    int i = 0;

    //set integer type variable and initialize to 0

    int j = 0;

    //set integer type variable and initialize to - 99

    int maxMiles = - 99;

    //set integer type variable and initialize to - 99

    int minMiles = - 99;

    //initialize the value in the two dimensional array

    milesTracker[0][0] = - 10;

    milesTracker[0][1] = 20;

    milesTracker[1][0] = 30;

    milesTracker[1][1] = 40;

    //here is the solution

    maxMiles = milesTracker[0][0];

    minMiles = milesTracker[0][0];

    /*set for loop to find the minimum miles and maximum miles*/

    for (i = 0; i < NUM_ROWS; i++)

    {

    for (j = 0; j < NUM_COLS; j++)

    {

    //set if condition for maxMiles is the bigger than

    if (milesTracker[i][j] > maxMiles)

    //initialize milesTracker[i][j] to maxMiles

    maxMiles = milesTracker[i][j];

    //set if condition for minMiles is the smaller than

    if (milesTracker[i][j] < minMiles)

    //initialize milesTracker[i][j] to maxMiles

    minMiles = milesTracker[i][j];

    }

    }

    //print output

    cout << "Min miles: " << minMiles << endl;

    //print output

    cout << "Max miles: " << maxMiles << endl;

    return 0;

    }

    Output:

    Min miles: - 10

    Max miles: 40

    Explanation:

    Here, we define the main method and inside it:

    set two constant integer type variable and initialize to 2 set integer type two-dimensional array and pass constant variables in it. Set two integer type variable and initialize to 0 then, again set two integer type variable and initialize to - 99. Initialize the values in the two-dimensional array. Set two for loop for the two-dimensional array to find the minimum and maximum miles. Set two if condition to find bigger or smaller miles.

    Finally, print the maximum and the minimum miles then, return 0.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers