1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
madreJ [45]
2 years ago
15

Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If user

Values is {2, 1, 2, 2} and matchValue is 2 , then numMatches should be 3. Your code will be tested with the following values:
matchValue: 2, userValues: {2, 1, 2, 2} (as in the example program above)
matchValue: 0, userValues: {0, 0, 0, 0}
matchValue: 10, userValues: {20, 50, 70, 100}
#include
#include
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 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;
}
Computers and Technology
1 answer:
Sedbober [7]2 years ago
3 0

Answer:

Replace /* Your solution goes here */ with:

cin>>matchValue;

numMatches = 0;

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

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

{

numMatches++;

}

}

Explanation:

This line gets input for matchValue

<em>cin>>matchValue; </em>

This line initializes numMatches to 0

<em>numMatches = 0; </em>

The following iteration checks for the number of matches (numMatches) of the matchValue

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

<em>if(matchValue == userValues.at(i)) </em>

<em>{ </em>

<em> numMatches++; </em>

<em>} </em>

<em>} </em>

<em>See Attachment for full source code</em>

Download cpp
You might be interested in
Answers please !!!!!!!!!!!!!!!!!!!!!!!!!!!
alina1380 [7]
Hard to see please add a better image. Actually just type out the question.
4 0
3 years ago
Which of the following sentences uses correct punctuation? A. I am a good communicator, and I am a strong team member. B. I comm
adelina 88 [10]
A has a comma then and so that isn't correct
B should be and I am
D should have an and in it
C is correct
7 0
3 years ago
Read 2 more answers
Which of the following is a characteristic of the college savings plan
Hoochie [10]

add the choices please

8 0
3 years ago
Read 2 more answers
Which Operating System is used most often in households?
pshichka [43]

Answer:

Windows

Explanation:

Windows are one of the most popular household os.

3 0
2 years ago
Read 2 more answers
This type of technology typically does NOT come with a keyboard or mouse for input.
anyanavicka [17]
The answer is C) tablet. You use the touch screen keyboard for that.
4 0
2 years ago
Read 2 more answers
Other questions:
  • What does N represent when analyzing algorithms?
    15·1 answer
  • Select the best answer for the question. 19. While broadcasting a football game, the announcer exclaimed, "I can't believe it. C
    7·2 answers
  • When people talk about "the media," they often mean:?
    6·1 answer
  • The browser on which you are viewing web pages is called the
    13·1 answer
  • Why did Herman Hollerith invent the Tabulating Machine?
    10·1 answer
  • Which is a benefit of using the paste link option?
    15·2 answers
  • ___ design uses the same webpage content, but applies styling depending on the viewport size of the device
    11·1 answer
  • Temperature converter. This program should prompt the user for two arguments, first a decimal number and second, a single letter
    10·1 answer
  • What is the difference between autofocus and autocomplete
    8·1 answer
  • When you run your Windows Form application, what is the lifespan of a global variable (also known as a "field" or "class" variab
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!