FAQ: Variables - Chaining

This community-built FAQ covers the “Chaining” exercise from the lesson “Variables”.

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

Learn C++

FAQs on the exercise Chaining

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 do not see the output window.
I do not have terminal

This question confused me because of the brackets. I had -

int score = 0;
std::cout << "Player score: [" << score << "]\n";

Could not figure out why it wouldn’t accept that answer.

3 Likes

Okay, I don’t get it. Where is a window that shows any output from the program. I write the code, compile and execute but where is the output. When you write HTML
it comes up in a browser. Where is the output for the C++?

that depends, if you use std::cout, usually to the console from which you execute the program. See documentation:

http://www.cplusplus.com/reference/cstdio/stdout/

of course, once you are a bit further along with C++, you could build your own graphical interface with libraries like QT. Then starting your program starts a graphical window. Usually, you first work in the command line to get the basics of c++ down

HTML is just a markup language, so yes, there the HTML is rendered in the browser.

because of your square brackets ([])

the square brackets in the example are only there to indicate what the variable is you should replace.

One thing that I felt was a bug is that you have to hit the Run button before compiling. I didn’t see that listed anywhere. I’m guessing that saves the file, and being used to environments that autosave is a step some people might not be used to.

2 Likes

So why do the square brackets become part of the output if they were not specified in the source code. I get the feeling the output is canned, and not really a result of compiling.

Why can’t I see the output after compiling and executing the code in C++?

Currently running through the tutorials to see if it would be good for new people in the lab I work in. For some reason, code identical to the solution code(and what would work in a normal terminal) didn’t output anything at all. Maybe a bug??

1 Like

I just rechecked the lesson in question, and everything seems to be working. Is it possible that you didn’t click “Run” before compiling? There is no auto-save feature. While “Run” may be a bit misleading, it saves your code. If you don’t click “Run” prior to compiling after making changes in the code editor, the compiler just re-compiles whichever code had been saved previously. If that’s not the fix, please post your code. Hope this helps!

I did hit run, but I closed it, reopened, ran it again, and am unable to replicate the error. Talk about a cliche…

I have noticed that on occasion the browser in the rightmost pane loses it’s connection, and has to be refreshed by refreshing my browser. Not really anything we can do other than deal with it and press on. :slightly_smiling_face:
Here’s a link to the Codecademy Troubleshooting Guide
It has information regarding which browsers and devices will yield the best results, and a few basic tips for when gliches happen.
Happy Coding!

Why does it keep saying error fatal error this file does not exist in the terminal?

What are you typing in the terminal that is generating the error?

Out of curiosity, I tried leaving off the additional << operator after the score variable

#include

int main() {

int score = 0;

// Output

std::cout << "Player score: " << score;

}

It returns the amout of the score but has a dollar sign immediately after. Can anyone tell me what this dollar sign means? If I add the extra operator and then the ; " <<;" the program will not compile. Do I always need to follow a variable with a new line “\n”?

The dollar sign is just the prompt for the console. Your next command will be typed to the right of the dollar sign. Adding a new line "\n" to the end of any std::cout << statement will just move the prompt or the next printed value down to the next line similar to hitting ‘enter’ or ‘return’ in a word processor or text editor.

3 Likes

Thanks! I wasn’t paying attention to the dollar signs in front of each line in the console.

2 Likes

so I’m trying to pass this level of this chaining but when I input what’s is exactly asking me it keeps saying “Did you output the exact phrase using chaining? Take a look at the hint if needed.” I’m not understanding what I’m doing wrong or if its a bug in the system. I input everything as the same as the hint

#include <iostream>

int main() {
  
  int score = 0;
  
  // Output
std::cout << "player score: " << score                                                                                    << "n/";
   
}

Hello, @cloud3640311884. Welcome to the forum. Here are the instructions:

Inside game.cpp , we have declared and initialized an int variable called score .

Now output the following using chaining:

Player score: [score]

where [score] should be the value of the variable score .

Make sure to add a new line after! //looks like you may have skipped this part

See the very last instruction.

1 Like