I'm stuck in Whale Talk (Codecademy)

https://www.codecademy.com/courses/learn-c-plus-plus/projects/cpp-whale-talk
I have the code:

#include <iostream>
#include <vector>
#include <string>

int main() {

  // Whale, whale, whale.
  // What have we got here?

  std::string input = "turpentine and turtles";

  std::vector<char> vowels = {'a', 'e', 'i', 'o', 'u'};

  std::vector<char> result;

  for (int i = 0; i < input.size(); i++) {

    for (int j = 0; j < vowels.size(); j++) {

      if (input[i] == vowels[j]) {

        result.push_back(input[i]);

      }

    }

  }

  for (int k = 0; k < result.size(); k++) {

    std::cout << result[k];

  }

  if (input[i] == 'u' || input[i] == 'e') {

    result.push_back(input[i]);

  }

}

When I try to run it, I get the message:

whale.cpp: in function 'int main()':
whale.cpp:36:13: error: "i" was not declared in this scope.
    if (input [i] == 'u' || input [i] == 'e') {
                   ^

I don’t understand why I am getting this message, or how to fix it.

Hello!
‘scope’ refers to what part(s) of the program can access different variables.
i.e. a global variable can be accessed anywhere. but a local variable is more restricted.
In your program, i is a local variable. It’s getting initialised at the start of the for-loop, and you can use it inside the loop.
But once the loop has ended, it gets discarded.

To fix your issue, you need to move the if statement into the for (int i …) code block.
So, that section of code would be;

for (int i...){
    for (int j...){
        if (input[i]...){
            result..;
        }
    }
    if (input[i] =='u' ...){    <- THE MOVED CODE <-
         result...;
    }
}

Hope that helps