- #1
osu3124
- 3
- 0
Problem Statement:
Resize vector countDown to have newSize elements. Populate the vector with integers {newSize, newSize - 1, ..., 1}. Ex: If newSize = 3, then countDown = {3, 2, 1}, and the sample program outputs:
3 2 1 Go!
Code I have so far, it works but I don't understand how to populate the vectors with integers counting down.
Resize vector countDown to have newSize elements. Populate the vector with integers {newSize, newSize - 1, ..., 1}. Ex: If newSize = 3, then countDown = {3, 2, 1}, and the sample program outputs:
3 2 1 Go!
Code I have so far, it works but I don't understand how to populate the vectors with integers counting down.
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> countDown(0);
int newSize = 0;
int i = 0;
newSize = 3;
countDown.resize(newSize);
for (i = 0; i < newSize; ++i) {
cout << countDown.at(i) << " ";
}
cout << "Go!" << endl;
return 0;
}