FAQ: Functions: Scope & Flexibility - The Scope of Things

This community-built FAQ covers the “The Scope of Things” exercise from the lesson “Functions: Scope & Flexibility”.

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

Learn C++

FAQs on the exercise The Scope of Things

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!
You can also find further discussion and get answers to your questions over in Language Help.

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

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

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, Anybody had an issue with this one? I cant seem to get it right although it execute as expected. Do advise thanks.
#include

void enter_code(int passcode) {

if (passcode == 0310) {

std::string secret_knowledge = “https://content.codecademy.com/courses/regex/onyourexcitingjourneylearningtocodeyouwillfindthis.gif”;
std::cout << secret_knowledge << “\n”;

} else {

std::cout << "Sorry, incorrect!\n";

}
}

int main() {

enter_code(0310);

}

3 Likes

I had the same problem where I had the same solution that as theirs but it wouldn’t be accepted. I just accepted their solution and continued on.

2 Likes

i have the same problem

1 Like

your just a robot how do you know

I am constantly have issues were no matter what I do the code I entered is wrong even though I’m getting the correct output. I have reported it as a bug multiple times but Code-academy.com seems to not care. This is the reason I refuse to pay for pro, if the free version does not work right half the time why would the pro version be any different.

2 Likes

I fixed the code like this : #include
void enter_code(int passcode) {
std::cout << “Enter your passcode! \n”;
std::cin >> passcode;
if (passcode == 1337) {
std::string secret_knowledge = “https://content.codecademy.com/courses/regex/onyourexcitingjourneylearningtocodeyouwillfindthis.gif”;
std::cout << secret_knowledge << “\n”;
}
else {
std::cout << “Sorry, incorrect!\n”;
}
}

int main() {
enter_code(1337);

}
when using 1337 or 0000 the code works, but when using 0310 it says that the passcode is incorrect. anyone has idea why so? edit: i noticed, when putting in 0310 it appears as int 200, so when u enter 200 it is correct for some reason

I tried that solution and it still said it was incorrect

i mean it says it is incorrect, but if you compile it in visual studio or somewhere else, the code will work

…and two years later:

Interesting! I was also curious about the literal integer. Why did they use the leading zero “0310”? and why does the code stop working if I change it to "enter_code (310) without the leading zero?? Well…

I discovered that in c++ when you enter an integer literal with a leading zero, the compiler interprets it as an octal number (base 8). Octal 0310 = decimal 200. So if you leave the passcode == 0310, and change it to "enter_code(200) it works, because decimal 200 = Octal 0310. Cool. Learn something everyday.

#include

void enter_code(int passcode) {
std::cout << “Enter your passcode! \n”;
if (passcode == 1337) {
std::string secret_knowledge = “https://content.codecademy.com/courses/regex/onyourexcitingjourneylearningtocodeyouwillfindthis.gif”;
std::cout << secret_knowledge << “\n”;
}
else {
std::cout << “Sorry, incorrect!\n”;
}
}

int main() {
enter_code(1337);
}

If you try this code it works.

Just a quick note for a suggestion in improving the lesson text. In first example it says:

" When this program is compiled and executed, sea_animal will print, but animal won’t. Why do you think that’s the case?".

This isn’t quite right. Code actually won’t compile because “animal” declaration isn’t available within main the way it is declared in the example. I confirmed on both Codecademy compiler and my desktop.

and another two years later here i am reading this very intriguing reply.