#include <vector>
#include <iostream>
usingnamespace std;
//forward declarations
vector<int> getEvenNumbers(int n);
void printVector(const vector<int> & v);
int main()
{ vector<int> v = getEvenNumbers(10); //even numbers from 2 to 20
printVector(v);
cout << endl;
return 0;
}
//function to generate even numbers
vector<int> getEvenNumbers(int n)
{ vector<int> v(n);
while (v[n] % 2 == 0) //to make sure the # is even
{
v.push_back(n);
}
return v;
}
//Function to print a (small) vector of integers
void printVector(const vector<int> & v){
cout << "{";
for (int i = 0; i < v.size(); ++i){
cout << v[i];
if(i < v.size() - 1){
cout << ",";
}
}
cout << "}";
}
My code is all over the place and doesn't even make sense, and it doesn't run because I think my function to generate even numbers is all wrong, but i have no idea how to fix it, any hints would be awesome!