vector < int > oddNumbers(int l, int r)
This is a function. The function is named oddNumbers. The function returns an object of type vector<int>. The function accepts two parameters, an int named l and an int named r.
oddNumbers is the name of the function.
So when you do this: oddNumbers.size()
it makes no sense because oddNumbers is a function name, and when you do this: oddNumber[r]
it makes no sense because you never created anything named oddNumber, and when you do this: odd[r]
it makes no sense because you never created anything named odd.
vector < int > oddNumbers(int l, int r) {
for (int i = l; i <= r; i++) {
if ( i % 2 == 1) {
//you found the odd number
} else {
//you found the even number
}
}
return /*what you found*/;
}
I don't know what to put in the comments. could you guys help me?
vector<int> oddNumbers(int l, int r) {
vector<int> result; // create the vector<int> to store the result
for (int i = l; i <= r; ++i) // for each number in the interval:
if (i % 2) // if i is odd:
result.push_back(i); // add i to the vector
return result; // give the vector to the caller
}