I realize that your assignment was due about two hours ago or so, but you still might like a quick explanation of "non void functions with arguments".
each function needs to have a
return type.
each function can take
parameters / arguments.
The two concepts are completely decoupled from one-another.
Note: There is a small difference between
parameters and arguments, but it's nothing a beginner should have to worry about. In a sense, it's merely a naming convention.
When a function terminates, it returns something to the calling function / process. The function
return type is what determines what the type of the thing that's being returned is.
If a function has a
void
return type, that means it doesn't return anything. If a function is
non-void, it has to return something. If a function is
void, it cannot return something.
Parameters / arguments are things you pass into the function. They can affect the flow or outcome of the function. For instance, depending on an argument, the value that a function returns could be different.
Here's an example of a function with a void return type (returns nothing), and no parameters / arguments:
1 2 3
|
void printHello() {
std::cout << "Hello" << std::endl;
}
|
Here's an example of a function with an int return type (returns an integer), and no parameters / arguments:
1 2 3
|
int retThreePlusFive() {
return 3 + 5;
}
|
Here's an example of a function with a void return type (returns nothing), and takes one string parameter / argument:
1 2 3
|
void printString(std::string string) {
std::cout << string << std::endl;
}
|
Here's an example of a function with an int return type (returns an int), and takes two int parameters / arguments:
1 2 3
|
void add(int a, int b) {
return a + b;
}
|