check if a value is odd and print odd numbers

I need to write a function that print the value of a given vector.
The value of left is 2 and the value of right is 5.
Input [2 5 ]

Output [3 5]
1
2
3
4
5
6
7
8
9
10
11
vector < int > oddNumbers(int l, int r) {

   for ( int r =0; oddNumbers.size(); r++){
       if (oddNumber[r] % 2 == ){
           cout << odd[r]%2;
           
       }
       else
           odd[0];
   }
}


It is not working.... help?
print the value of a given vector.

Where is your vector?
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.

http://www.cplusplus.com/doc/tutorial/functions/

print the value of a given vector.

What is the "value" of a vector?
Last edited on
I see. So i need to create my vector then?this is a practice in which I need to implement a solution.
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?
1
2
3
4
5
6
7
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
}
Last edited on
Topic archived. No new replies allowed.