The structure & syntax...
This is the function prototype. It tells the compiler the name of the function, the type of return value, and the types & quantity of values passed-in.
Code:
int mult ( int x, int y );
This is the function definition. It's the "real code" for the function.
Code:
int mult ( int x, int y )
{
return x * y;
}
mult(x,y) is the function call. It "runs" the function.
Code:
cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
Code:
Z = mult((x, y); // Another way to call the function
A function is...
Something like a mini-program...
Here, you are running main(), and you get to the function-call, and the program-flow jumps to the mult() function. When the function ends, it returns back to main, and it brings-back a value... an int which is x * y.
You can call a function as many times as you want. In fact, this is (mostly) why they are used. You only have to include the code for your function once, but you can call it many times. No one would actually write a function like the example. There is no need for a multiply function, since multiplication is built-into C++.
cin is for "C Input" (from keyboard, etc)
cout is for "C Output" (to display, etc)
The extra cin.get() is there to make the program work on a Windows system. It just keeps your program from ending and closing the window before you can read the output.
A few more notes & comments...
You can pass as many values into a function as you wish, but a function can only return one value. (There are ways using pointers and references to affect more than one variable.)
Make sure you understand functions. Everything in C++ is done with functions!
The variable names are optional in the function prototype and are ignored by the compiler. Sometimes the names are helpful to us humans if they are meaningful... "Width", "Height", etc.
Code:
int mult( int , int );// This is OK
int mult(int Number1, int Number2); // This is OK too
The variable names passed-into the function can be different than the names inside the function. Only the value is passed-in, not the actual variable.
Code:
cout<<"The product of your two numbers is "<< mult ( A, B ) <<"\n"; // This will work if A & B are defined ints
cout<<"The product of your two numbers is "<< mult ( 2, 4 ) <<"\n"; // This will work too