I'm stuck in Whale Talk (Codecademy)

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]) {





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

    std::cout << result[k];


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




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.

‘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]...){
    if (input[i] =='u' ...){    <- THE MOVED CODE <-

Hope that helps