// moreCalls.cpp

#include <iostream>

using namespace std;

// Function prototypes:
int first (int);
void second (int&);
void third (int);


int main ()
{
   int i = 10;
   cout << "Line 16: main begins:          i = " << i << endl;
   i = first( i );
   cout << "Line 18: main ends:            i = " << i << endl;
   return 0;
}  // function main


int first ( int j )
{
   cout << "Line 25: first begins:         j = " << j << endl;
   if ( j % 3 == 2 )
      j++;
   else
      j--;
   cout << "Line 30: first calls second:   j = " << j << endl;
   second( j );
   cout << "Line 32: first calls third:    j = " << j << endl;
   third( j );
   cout << "Line 34: first ends:           j = " << j << endl;
   return( j+1 );
}  // function first


void second ( int& k )
{
   cout << "Line 41: second begins:        k = " << k << endl;
   k = k + 4 * 2;
   cout << "Line 43: second calls third:   k = " << k << endl;
   third( k );
   cout << "Line 45: second ends:          k = " << k << endl;
}  // function second


void third ( int n )
{
   cout << "Line 51: third begins:         n = " << n << endl;
   int i = 0;
   while ( i <= 3 ) {
      for ( int j = 0; j < i; j++ ) {
         n++;
      } // for j
      i++;
   } // while i
   cout << "Line 59: third ends:           n = " << n << endl;
}  // function third