- #1
needOfHelpCMath
- 72
- 0
I would like some help or guide to if i am going on the right track on my program ***Set numMatches to the number of elements in userValues (having NUM_VALS elements) that equal matchValue. Ex: If matchValue = 2 and userValues = {2, 2, 1, 2}, then numMatches = 3. ***
**MY TEST**
Testing matchValue = 2,
userValues = {2, 2, 1, 2}
Expected value: 3
Your value: 9
Code:
#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= userValues.at(0);
for (i = 0; i < NUM_VALS; ++i)
{
cin >> userValues.at(i);
}
for (i = 0; i < NUM_VALS; ++i) {
numMatches = numMatches + userValues.at(i);
}
cout << "matchValue: " << matchValue << ", numMatches: " << numMatches << endl;
return 0;
}
**MY TEST**
Testing matchValue = 2,
userValues = {2, 2, 1, 2}
Expected value: 3
Your value: 9