Activity 4-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 the previous 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 4.4
The following function will use 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.

Write the complete program, ex43.cpp, compile and run it.

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;
}