- #1
medonaldson2
- 2
- 0
So I'm trying to do this problem:
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}.
Here is my code so far...
The output is when tested with values {2, 4, 6}
02 4 6
The output needs to be...
2 4 6
I don't know why the zero is there. Any ideas?
thanks
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}.
Here is my code so far...
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
const int NUM_GUESSES = 3;
vector<int> userGuesses(NUM_GUESSES);
int i = 0;
for (i = 0; i < NUM_GUESSES; i++) {
cin >> userGuesses[i];
}
cout << userGuesses[i];
return 0;
}
The output is when tested with values {2, 4, 6}
02 4 6
The output needs to be...
2 4 6
I don't know why the zero is there. Any ideas?
thanks