Hello everyone,
Apologies if this has already cropped up and been answered (I did look, but didn’t see it).
I am working on the Whale Talk section. Hopefully the link will work:
https://www.codecademy.com/courses/learn-c-plus-plus/projects/cpp-whale-talk
Before I put my code below, my problem seems to be that when the for loop looks through the test phrase for vowels, it isn’t identifying the letter “i”. The test phrase was “turpentine and turtles”. I’m also ending up with way too many vowels, even allowing for doubling certain ones, but I will tackle that myself, once I know what I am doing wrong with checking against the vowel vector. Code starts below:
#include
#include
#include
int main() {
// This does not work as I intended. Why doesn’t it pull the letter i?
// Whale, whale, whale.
// What have we got here?
std::string input = “turpentine and turtles”;
std::vector vowels = {‘a’,‘e’,‘i’,‘o’,‘u’};
std::vector result;
std::vector whale_talk;
// loop that iterates through the input string.
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]);
}
}
if (input[i] == ‘u’ || input[i] == ‘e’) {
whale_talk.push_back(input[i]);
}
for (int k = 0; k < whale_talk.size(); k++){
std::cout << whale_talk[k];
}
}
}
Thanks in advance,
David