// Program 6: AbsoluteDifference.C
// (c) Burt Rosenberg 1996
// This program introduces return values for functions.

#include<iostream.h>

int distance (      // Create a procedure object returning an
   int a, int b )   // integer object, and two integer objects.
                    // Initialize the integer objects.
{
   if ( a<b )
   {
      // b is larger than a.
      return( b-a ) ;   // pass this value back to the caller.
   }
   else
   {
      // a is at least as large as b
      return( a-b ) ;  // pass this value back to the caller.
   }
}

void main()
{
   // Create 4 integer objects.
   int i, abs_i ;
   int j, abs_j ;


   // Input 2 integers.
   cout << "Enter i:" ;
   cin >> i ;
   cout << "Enter j:" ;
   cin >> j ;


   // Calulate the absolute values of the integers.
   abs_i = distance( i, 0 ) ;
   abs_j = distance( j, 0 ) ;

  // Calculate and print the result.
  cout << "Abs( " ;
  cout <<    "Abs(" << i << ")" ;
  cout << " - " ;
  cout <<    "Abs(" << j << ")" ;
  cout << " ) = " << distance( abs_i, abs_j ) << endl ;

}



