I've tried looking online to help me, but I can't seem to understand it.
Does he want me to assign variables to firstname and lastname to display? If I were to do that, I can't figure out how I would do so since his examples are only with integers.
Blah, this isn't making any sense to me. :/ I'm sorry guys, I'm really trying hard to understand why or how this works, but the setup of these problems makes no sense.
I understand the concept that the Function is basically a template that will transform the data that is entered into main(). For example, if we define string::std firstPresident(first, last) as a function, I can enter a name in the main(), like string firstPresident (George, Washington) or if I wanted to change it up, (Jimmy, Carter)
string first, last in main() is not the same thing as string first, last in firstPresident(). They're staying local to the function they've been defined in.
The HelloWorld( ) function returns "Hello world!". So, when you call HelloWorld( ), it's essentially the same thing as just writing out "Hello world!" instead.
Return values can be any type. They can be int, void, bool, std::string, whatever you want. In this case, HelloWorld( ) returns std::string, which is a type "cout" understands.
Anyways, when you run the program, this is what happens:
1 2 3 4 5 6 7
int main( )
{
// cout << HelloWorld( ); <-- The compiler resolves the function return, and you get this:
cout << "Hello world!";
return 0;
}
#include <iostream>
#include <string>
usingnamespace std;
std::string stringFunction(string first, string last)
{
//initialize any needed variables here
//construct your function to combine (concatenate) the strings here
//return the result here
}
int main()
{
string first, last, result;
result = stringFunction( first, last );
cout << result;
}