Assign numMatches with the number of elements in userValues that equal match Value. userValues has NUM_VALS elements. Ex: If userValues is {2, 1, 2, 2} and matchValue is 2 , then numMatches should be 3.#include #include using namespace std;int main() { const int NUM_VALS = 4; vector userValues(NUM_VALS); int i = 0; int matchValue = 0; int numMatches = -99; // Assign numMatches with 0 before your for loop userValues.at(0) = 2; userValues.at(1) = 2; userValues.at(2) = 1; userValues.at(3) = 2; matchValue = 2; STUDENT CODE cout << "matchValue: " << matchValue << ", numMatches: " << numMatches << endl; return 0;}

Respuesta :

Answer:

#include <iostream>

#include <vector>

using namespace std;

int main()

{

const int NUM_VALS = 4;

vector<int> userValues(NUM_VALS);

int i = 0;

int matchValue = 0;

int numMatches = -99; // Assign numMatches with 0 before your for loop

userValues.at(0) = 2;

userValues.at(1) = 2;

userValues.at(2) = 1;

userValues.at(3) = 2;

matchValue = 2;

numMatches=0;

//loop to iterate elements of userValues

for(int i=0; i<NUM_VALS; i++)

{

//check the matchValue with every element of the userValues using index

if(userValues.at(i)==matchValue)

numMatches++;

}

//STUDENT CODE

//print the result

cout << "matchValue: " << matchValue << ", numMatches: " << numMatches << endl;

return 0;

}

Explanation: