Oscar A.

asked • 04/12/20

Assign numMatches with the number of elements in userValues that equal matchValue.

Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 2, 1, 2} and matchValue is 2 , then numMatches should be 3.


Your code will be tested with the following values:

* matchValue: 2, userValues: {2, 2, 1, 2} (as in the example program above)

* matchValue: 0, userValues: {0, 0, 0, 0}

* matchValue: 50, userValues: {10, 20, 30, 40}


#include <iostream>

#include <vector>

using namespace std;


int main() {

const int NUM_VALS = 4;

int matchValue;

unsigned int i;

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

vector<int> userValues(NUM_VALS);


cin >> matchValue;


for (i = 0; i < userValues.size(); ++i) {

cin >> userValues.at(i);

}


/* Your solution goes here */


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


return 0;

}

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.