Activity 6-3 - Function Calling Another Function



You have already seen a function that has called another function, but you may not have paid close attention to it.  In the previous labs, you called a predefined function from the main.  You also called the function get_input from the main function in a previous part of the lab.  In order to call a function inside another function, you need to have the declaration of the function that is being called before the declaration of the calling function.
Here is an example:

void that_function(double& x );
double this_function( ); //This function can now call that function

int main( )
{
     double y;
     ....
     ....
     y = this_function( );

     ....

     return 0;
}

double this_function( )
{
      double x;
      ....
      ....
      that_function(x );  // that function is being called inside this function

      return x;
}

void that_function(double& x )
{
    ....
    ....
}

Exercise 6.4
Consider the following function that uses a, b, and c as the coefficients of a quadratic equation to compute b2 - 4ac.   This function calls on another function called get_a_b_c to get the values for a, b, and c.

double bb_4ac( )
{
        double a, b, c;  // Coefficients of a quadratic equation
        get_a_b_c(a, b, c);

        return b*b - 4*a*c;
}

Complete the program by writing the main function (sometimes also called the "driver" function) that calls the above function. Compile it and run it.