When making my functions, they always confuse me except when it's a void menu () function.
I get really confused when making it so i end up putting everything in int main() .
What do you do when/before writing functions?
Thanks.
Functions are very cool and useful in C++.
First of all the primary reason for which one will create a function is that one would want to do some complex stuff, elsewhere(not in main) or at least wants his programme to look organized.
The <return type> tells the data type the function would return to its caller. eg: int would return an integer
<function name> is the desired ID of the function
<parameters> are the extra data passed to the function by the caller
eg:
1 2 3 4 5 6 7
int add(int a,int b) {return (a+b);}
int main()
{
cout<<add(2,3);
return 0;
}
The add function is called passing 2 and 3 as parameters.
The function then does the addition and returns the sum, of variable type int to main()
The main function then outputs the result.