/*
  Name: funcs06.cpp
  Compiler: Dev-C++ 4.9.9.2
  Copyright: 2006
  Author: Anne Dawson
  First created: 23/09/99
  Last updated:  21/01/06 5:58
  Description: This program sends two numbers to a function,
               the function adds the numbers and returns their sum to
               the main function. A predefined function - sqrt() is 
               then used to calculate the square root of the sum.
               The square root of the sum is then multiplied by 3
               using a global contant (a global constant is declared
               before any function, and can be used in any function).
*/

#include <iostream> 
#include <cmath> // for sqrt() function and other math functions
using namespace std;

const int TRIPLE = 3; // a global constant

double display_the_number(int number1, double number2); 
// the function prototype (function declaration)
// this function receives two numbers and returns their sum

/**********************************************************************/


int main() 
{   // start of main function
	int num1 = 122;
	double num2 = 1.45;
	double result, square_root_of_result;


	result = display_the_number(num1,num2); // a call to the function 
	cout << endl; // sends an end of line character to the screen 
	cout << endl; // sends an end of line character to the screen 
	cout << "The sum of " << num1 << " and " << num2 << " is " << result;
    cout << endl << endl;
   	square_root_of_result = sqrt(result);
	cout << "The square root of " << result << " is " << square_root_of_result;
	cout << endl << endl;
	cout << "This result multiplied by three is: " << square_root_of_result * TRIPLE;
	cout << endl << endl;

	cout << "Press any key to end the program";
    cout << endl << endl;
	system("Pause"); // waits for a key to be pressed by user
    return 0; // returns integer 0 to operating system
}   // end of main function

/**********************************************************************/

double display_the_number(int number1, double number2)
// the function prototype (function declaration)
// this function receives two numbers and returns their sum
{
   double sum;

	cout << "Now in the display_the_number() function" << endl << endl;

	// send the value of number1 to the console output i.e. screen 
	cout << "Number 1 : " << number1;
	cout << endl; // sends an end of line character to the screen 
	cout << endl; // sends an end of line character to the screen 
	
	cout << "Press any key to see number2";
	cout << endl; /* sends an end of line character to the screen */
	cout << endl; /* sends an end of line character to the screen */
	system("Pause"); // waits for a key to be pressed by user
	
	/* The following 3 lines are needed to display the double as required */
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	cout << endl << "Number 2 : " << number2;
	/* send the value of number2 to the console output i.e. screen */


	cout << endl; /* sends an end of line character to the screen */
	cout << endl; /* sends an end of line character to the screen */

	sum = number1 + number2;

	cout << "Press any key to end the function";
	cout << endl; /* sends an end of line character to the screen */
	cout << endl; /* sends an end of line character to the screen */
	system("Pause"); // waits for a key to be pressed by user

	return (sum);
}

/**********************************************************************/

