If you want to return a value, you need something for it to ride with. These are the declarations before the function name. Int, string, etc etc . You are saying: This function is going to do some stuff, and return it in the value type I've added before the function name. You can't hitch a ride with no wheels.
Functions can do stuff without returning any data. EG. just print out a message. Or they can do stuff and return data and values back into the wider programme. EG. adding points to a game, maybe doing some math and returning the calculations.
I got confused with cout vs return because I didn't understand that cout was looking inside and reading what it saw. return was taking that data and dumping it into another part of the program.
with a function that returns a value, you need to express in this way:
int function_name(int a)
{
return a;
}
//int - This is the value type I want this function to grab and return back to the program. You choose which type to use.
// function_name -this is the name of the function - replace with your own
// stuff in brackets (this is the data type I will be adding into the function- numbers, words, characters, true/false etc)
// curly brackets - this is what my function will do.
//return ... (also inside the brackets: this is what data I want to transport back to the bigger programme with my value type I told you I wanted to use at the start of the function declaration.
{
This is the stuff my function is going to do. Here is a template for the programme to follow.
Please take this value, and take its value back to the programme.
}
{
return a;
}