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!

Hi!
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:

2 Likes

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?

vs.

Some text here
?
2 Likes

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.

Regards,

José

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:

It says that in order to complete the task I have to input

if (grade > 60) {

std::cout << “Pass\n”;

}

but when I put the ‘>’ It shows up as red instead of as white like it shows it’s supposed to in the hint, and idk what to do now.

1 Like

In the IF statement section, page 3/8, it says to write the if statement for grade>60 then Pass, but it has the coinflip code open and I can’t open the grade code. Someone should check the lesson to make sure it’s outputting the right material.

Try to refresh the page and perhaps the correct content will be there.

In the IF statement exercise (about grade > 60), it doesn’t like it when someone changes the actual int = 90, to, for example int = 61 (like I did, for experiment’s sake). Not a biggy, but I was confused a while, since I knew I am writing the code right, but the terminal kept spitting out errors. Perhaps it could be a good idea to set it up, so people can actually play around with the grade numbers themselves :wink:

Hello, @lixypixy, and welcome to the forums.

After you’ve passed the SCT for the exercise, you can change the code to experiment with additional/alternative values, and change the code. If you changed it prior to passing the exercise, the SCT probably spit out some red text complaining that you didn’t follow the instructions, but you shouldn’t have seen any actual errors.

2 Likes

Hi @midlindner !
Thanks for the welcome!
And yeah - I did it prior to passing the exercise and it was spitting out some errors about the “if” not having values, or…something. I can’t remember it precisely right now! But all’s good anyways now, so thanks for the answer :slight_smile:

1 Like

Oh, that’s just syntax highlighting, we programmers like it :wink: dw it won’t effect anything.