C++ loops

C++: Loops within ConditionalsWhen you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Hello @alexwilliams17038626!

Is there a specific question you’d like to ask?

1 Like

How do I get the compiler to output what the exercise say’s it should be? I entered “g++ whale.cpp” and I got the prompt to enter “./a.out” and then it skipped down a line and that’s where I’m stuck.

Hello, @alexwilliams17038626. Please post your code following the guidelines in this topic How do I format code in my posts?. We may also need to see a screenshot to understand exactly how you’re stuck. A link to the exercise would be helpful as well.

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

int main() {
  // Whale Talk.

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

www.codecademy.com/courses/learn-c-plus-plus/projects/cpp-whale-talk
This is the code and the link. In that order.

The end of your code is missing. For blocks of code to display correctly they should have three backticks on the line above the code, and three backticks on the line below the code:
image

\
#include
#include
#include

int main() {
// Whale Talk.

std::string input = “turpentine and turtles”;

std::vector vowels = {‘a’,‘e’,‘i’,‘o’,‘u’};
std::vector 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]);
\\\

[www.codecademy.com/courses/learn-c-plus-plus/projects/cpp-whale-talk](http://www.codecademy.com/courses/learn-c-plus-plus/projects/cpp-whale-talk)
This is the code and the link. In that order.

Backticks

`

not backslashes

\

The backtick on my keyboard is right below the escape key. Also, the end of your code is missing. Where are all of the closing braces?

#include
#include
#include

int main() {
// Whale Talk.

std::string input = “turpentine and turtles”;

std::vector vowels = {‘a’,‘e’,‘i’,‘o’,‘u’};
std::vector 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]);

Your code can’t end there. That wouldn’t even compile. What do you have after:

  result.push_back(input[i]);

?
It looks like you copied the code from your first post here. Copy the code from the exercise on the main Codecademy site, and paste it in a new reply.

Without all of the code, it’s impossible to say what the problem might be. If that is all of the code, then you need a closing brace } for every opening brace {.

Thank you. I’ll try that.