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 () 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 () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Can someone explain what is mean by a function having “no return value” please. The code below is returning something, given the parameters of “Beyonce”, “Knowles” is it not? so wouldn’t that be a value?
// function prototypes: getname, introduction (required if defining functions below main() )
void getname(std::string &first_name, std::string &last_name); // passing first name and last name by reference/memory
void introduction(std::string first_name, std::string last_name);
void getname(std::string &first_name, std::string &last_name) // prompts user for input
{
std::cout << "Enter first name: ";
std::getline(std::cin, first_name); // gets user’s string input
std::cout << "Enter last name: ";
std::getline(std::cin, last_name);
}
void introduction(std::string first_name, std::string last_name) // displays to console the bond intro
{
std::cout << last_name << ", " << first_name << " " << last_name << "\n ";
}
int main()
{
std::string first_name, last_name;
getname(first_name, last_name); // calls getname function
introduction(first_name, last_name); // calls introduction function
}
//////////////////////////////basic version #include #include
This is so broken oml. Y’all need to fix this. It’s failing me even though I did what it asked. Cout is not a return value. I’ve been using this as a refresher, and I know cout is not a return value.
I checked and the “solution” is LITERALLY the same thing, but without “using namespace std;”. Are you kidding me? Why does this website hate optimization??!! Why do you keep using outdated “std::” when “using namespace std;” is one line that erases the need to constantly type that? What a load of baloney.
That’s my code ^ and in the console it shows “Knowles, Beyonce”, yet I get the prompt from codecademy “Does introduction() print the right message?”. I’m really not seeing the problem here
You are not meeting the exact specifications of the task. If a person’s first name was James and last name was Bond, then the function should output: Bond, James Bond
Your function would output: James, James Bond which is not the specified expected output.
If a person’s name is Beyonce Knowles, the expected output is: Knowles, Beyonce Knowles
Your function outputs: Beyonce, Knowles Beyonce which isn’t the same thing.
Read above as to the expected output. Your function doesn’t print the same thing.
This is the Correct Solution if you are confused. But pay attention to why the require correct spacing this was my error std::cout << last_name << “,” << first_name << " " << last_name; missing the space on the comma. LOL enjoy
I have the same little pet peeve as some others here, the solution doesn’t allow “using namespace std;” which is a bit confusing to me since fundamentally it does the same thing, but I understand the concept. I would love to have that fixed though.
The output is as expected i.e. Knowles, Beyonce Knowles, but you have changed the specifications mentioned in the instructions.
The instructions specify “no return value” whereas your function is returning a string. Also, your return type is std::string. Instead it should be void. The function is meant to print a statement, not return a value.
The instructions specify the parameters should be named first_name and last_name, whereas your parameters are named fst_name and lst_name
In main, the call should be
introduction("Beyonce","Knowles");
and the printing should be left to the introduction function.
Your call in main is
std::cout << introduction("Beyonce","Knowles");
with the main doing the printing and introduction returning a value. This doesn’t meet the specs in the instructions.
Hi, I wrote this code. It does what I want it to do in my personal IDE, but in the codecademy compiler it prints out the wrong information.
The code is: #include <stdio.h> #include #include
using namespace std;
//declares strings to be used without the function
string first_name;
string last_name;
//function to ask for users first and last name to print out the correct parameters
void introduction(std::string first_name, std::string last_name) {
std::cout << “What is your first name?\n”;
std::cin >> first_name;
std::cout << “What is your last name\n”;
std::cin >> last_name;
Can you elaborate on what is wrong in the printed information? Is there a problem with the output? Does the system give some error message/feedback?
In the Codecademy instructions, there is no mention of the user providing the input/arguments through prompts.
Other than that, the instructions specify:
The function should print the last_name, followed by a comma, a space, first_name another space, and finally last_name again.
introduction("James", "Bond");
// Expected Output: "Bond, James Bond"
// Your Output: "Bond, James Bond "
// Your code:
std::cout << last_name << ", " << first_name << " " << last_name << " \n";
// It should be:
std::cout << last_name << ", " << first_name << " " << last_name << "\n";
Your output has an extra trailing space. The automated system likely marks your output as incorrect because the extra space means your output is not an EXACT match of the expected output.