All functions have a type. Whether it be void, int or double (much more).
All functions except void return a value!
You notice that main returns 0? For example
- int main() {
-
cout << "HAHAHAHAH";
- return 0;
-
}
Well functions return values too (unless its a void). For example:
- int multiply_numbers(int x, int y) {
-
int new_value;
-
new_value = x * y;
- return new_value;
-
}
Void functions, on the other hand, don't require a return value at all. They are just run.
- void multiply_numbers(int x, int y) {
-
int new_value;
-
new_value = x * y;
-
//No return value!
-
}
Now still ambiguous, I will clear all your sinus problems up. For I shall demonstrate!
If I do this:
cout << multiply_numbers(x, y);
I'll get 10 if x = 2 & y = 5. BUT, that is ONLY IF the function was an integer. If it was a void...well that'd be ugly. Why? Well because void functions don't return anything. If its an integer, multiply_numbers(x, y) turns into 10. :)
It'd be useful to use void functions if you are welcoming the user. Such as:
- void welcome_user() {
-
cout << "Welcome to my Freaking Program!\n";
-
cout << "Bow to me because I Like Bananas!";
-
}
Other things too :). Thats it for now.