using c++ Set numMatches to the number of elements in uservalues (having NUM VAL
ID: 3666921 • Letter: U
Question
using c++
Set numMatches to the number of elements in uservalues (having NUM VALS elements that equal matchValue. Ex: If matchvalue 2 and uservals 12, 2, 1, 2), then numMatches 3. const int NUM VALS 6 int userVa esCNUM VALS lun int i 0; 8 int matchvalue 2; 9 int numMatches 0; Assign numMatches with 0 before your for loop user values [0] 12 userValues [1] 2; 13 user values [2] 1; 14 user values [3] 2; 16 matchvalue 2; 17 18 Your solution goes here 20 t matchvalue matchValue numMatches numMatches endl. 22 return 0 Run 6.4.2: Populating an array with a for loop Write a for loop to populate array userGuesses with NUM GUESSES integers. Read integers using cin. Ex: lf NUM GUESSES is 3 and user enters 9 52, then userGuesses is 19, 5, 2 1 #include iostream> 2 using namespace std; 4 int mainO const in NUMLGUESSES 3; 6 int user Guesses NUMLGUESSESJ; int i 0; 9 Your solution goes here 11 for Ci 0; i NUM GUESSES ++i) Cij cout ser Guesses 14 return 0Explanation / Answer
1.for (int i = 0; (i < n - 1); i++)
{
bool matching = false;
for (j = i + 1; (j < n) && (matching == false); j++)
{
if (numbs[i] == numbs[j]) {matching = true;}
if (matching)
{
cout<< numbs[i] << ", " << numbs[j];
cout << " j is equal to: " << j << " ";
matching = false;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.