Creating the local function
There are a variety of approaches you can take to do this. In this case, on a new line within our new function, type the following:
double c = CompareFirstTwo(x, y);
Here, we are creating a variable by calling a new function, so let's go ahead and create this function. Start a new line underneath the preceding statement and type the following:
double CompareFirstTwo(double a, double b) { }
With this, we've created a local function inside FindBiggestValue
. The use of our CompareFirstTwo
function is highly restricted to finding the biggest value. It doesn't really serve much of a purpose outside that, which is why I'm using it as a local function. Inside our new local function, type the following:
return (a > b) ? a : b;
So, we are using the ternary operator to compare the two values. If a
is greater than b
, return a
. Otherwise, return b
. If you want to, of course, you could actually just have a sequence of these ternary operators inside the main FindBiggestValue...