C++

Josh C.

asked • 10/28/20

Populating a vector with a for loop.

Write a for loop to populate vector userGuesses with NUM_GUESSES integers. Read integers using cin. Ex: If NUM_GUESSES is 3 and user enters 9 5 2, then userGuesses is {9, 5, 2}.


#include <iostream>

#include <vector>

using namespace std;


int main() {

const int NUM_GUESSES = 3;

vector<int> userGuesses(NUM_GUESSES);

unsigned int i;




}

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

cout << userGuesses.at(i) << " ";

}


return 0;

}

1 Expert Answer

By:

Patrick B. answered • 10/28/20

Tutor
4.7 (31)

Math and computer tutor/teacher

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.