There is a button next to the textfield where you type with "<>". If you click that you will get "code-tags" that enable you to post your source code in a more readable way. Please try to use them whenever you post some code.
I hope you are aware that you did not try to implement a function called smaller, you implemented a function called compareTwo that calls a (undefined) function called smaller.
Also, there is no difference between writing a smaller or a larger function. At least there should not be. A function is just a sequence of commands that you want the program to execute which you expect you will use more often. The number of commands in the sequence doesn't matter (except for the source-code-readers comfort).
It is important to realize that a if a function returns, the rest of the code will not be executed anymore. For example, here line 4 will never be executed, because the function call returns in line 3.
1 2 3 4 5
|
int fourtytwo()
{
return 42;
std::cout << " this will never be printed in the console because this line can not ever be executed." ;
}
|
Do you know if-statements?
If not, read this:
http://www.cprogramming.com/tutorial/lesson2.html
Your smaller function should take two arguments (for example x and y), then you should use an if-statement to check if the first is smaller that the other. If this if-statement is true, you return the first value.
If the if-statement is not true, you return the second value.
I don't understand why you want to call a function called smaller in your function compareTwo, since the compareTwo function does nothing else you could easily put your if-statement in there instead of the call to another function.
1 2 3 4
|
int compareTwo(int x, int y)
{
return (x < y) ? x : y; // return the result of this shorthand if-statement.
}
|
or, to prevent the shorthand from making it difficult to understand:
1 2 3 4 5
|
int compareTwo(int x, int y)
{
if (x < y) return x;
else return y;
}
|