Help with C++ Whale Project

I am a little lost on this project.

Can anyone help me interpret this error message?

Here’s my code:

Here’s the error message:

g++ whale.cpp whale.cpp: In function ‘int main()’: whale.cpp:29:2: error: ‘whale_talk’ was not declared in this scope whale_talk.push_back(input[i]); ^~~~~~~~~~ whale.cpp: At global scope: whale.cpp:46:3: error: expected unqualified-id before ‘for’ for (int k = 0; k < whale_talk.size(); k++) { ^~~ whale.cpp:46:19: error: ‘k’ does not name a type for (int k = 0; k < whale_talk.size(); k++) { ^ whale.cpp:46:42: error: ‘k’ does not name a type ; k < whale_talk.size(); k++) { ^ whale.cpp:51:8: error: ‘cout’ in namespace ‘std’ does not name a type std::cout << "\n"; ^~~~ In file included from whale.cpp:1:0: /usr/include/c++/7/iostream:61:18: note: ‘std::cout’ declared here extern ostream cout; /// Linked to standard output ^~~~ whale.cpp:52:1: error: expected declaration before ‘}’ token } ^

In C++, you have to declare whale_talk before you can start pushing values to it. Later when you try to print, you’ll have another issue. You might consider making whale_talk a string rather than a vector.

1 Like