FAQ: Conditionals & Logic - If Statement

This community-built FAQ covers the “If Statement” exercise from the lesson “Conditionals & Logic”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C++

FAQs on the exercise If Statement

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I know that this souldn’t be the lesson to ask this, but I’ll do it anyway:

–> You put in the tutorial:
std::cout << "Some text here\n";
But this also works fine:
std::cout << "Some text here";
Why sould we put the \n when it’s easyer to do it without it?

–> And the other question is that is it better to put more spaces when without them it works?:

bmi = weight/(height*height); [Without unnecessary spaces]
bmi = weight / (height * height); [With spaces]

I know that you don’t save a lot by doing this, but i wanted to know

Thanks :wink:

1 Like

If you watch closely you’ll see the ? prompt at the end of the line rather than on the next line. That is why we need to include the newline escape character, \n at the end of the cout string.

Some text here?


Some text here

yes, I noticed this a litle bit after. Thanks anyway, now I know it for shure and that it means newline escape character.

1 Like

Hello johnbrun,

About more spaces, this is how you are comfortable to read the code, if more spaces on code is good for you is ok, this is a detail that each programmer have, I think that it’s more about styles and likes to write code.



You put in the tutorial:
std::cout << "Some text here\n";
you should do it the right way which is
std::cout << “some text here” << std::endl;
please fix it!

Why do you say endl should be used here? :slight_smile: