// File: handyfunc.cxx 01/27/2010
// Written by: Dmitry Duplyakin (Dmitry.Duplyakin@colorado.edu)
// and Michael Main (main@colorado.edu)
// The purpose of this program is to show
// how to create functions which return values 

// Directives:
#include <iostream>
#include <cmath>
using namespace std;

//-----------------------------------------------------------------------------
// Function Prototypes.

// The dist function finds the distance between two points (x1, y1) and
// (x2, y2) with integer coordinates, for instance two pixels on the screen.   
// Now we can use it and prove the Pythagorean theorem! Isn't it great?
double dist(double x1, double y1, double x2, double y2);

// The fahr_to_cell function converts Fahrenheit temperature fahr to Celsius.
// From now on you can talk to your friends over in Europe or somewhere else
// and talk about the temperature so they can undersatand you! Do you like that?
double fahr_to_cel (double fahr);

// The lcm function calculates the least common multiple of two integer
// numbers a and b.
// Please do NOT use this function in real life! It's very slooooooooow and
// the program will run for years. Almost any other algorithm will work faster  
int lcm (int a, int b);

// The gcd function calculates the greatest common divisor of two
// integer numbers a and b.
// This algorithm was described by Euclid back in the day, somewhere
// around 300 BC. It's very efficient so we still use it today.
// Thank you, Euclid!
int gcd (int a, int b);

// The lcm_fast function calculates the least common multiple of two integer
// numbers a and b and does it very efficiently. 
// It uses gcd function to find the greatest common divisor of a and b.
// Thanks again, Euclid!
int lcm_fast (int a, int b);

//-----------------------------------------------------------------------------
int main()
{
    cout << dist(1.0, 2.0, 4.0, -2.0) << endl;
    cout << fahr_to_cel(32) << endl;
    cout << fahr_to_cel(212) << endl;
    cout << fahr_to_cel(-40) << endl;
    cout << lcm(21, 9) << endl;
    cout << lcm(121, 10001) << endl;
    return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
double dist(double x1, double y1, double x2, double y2)
{
    // cppreference.com has a list of the math stuff such as pow(x,y)
    // that computes x raised to the y power
    double answer = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
    return answer;
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
double fahr_to_cel (double fahr)
{
    return (fahr - 32) * (5.0/9.0);    
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
int lcm (int a, int b)
{
    int guess = a; // Our first guess is a. This is okay because the lcm >= a.

    // The || means "or"
    // Keep going when guess divided by a gives a non-zero remainder
    // or when guess divided by b gives a non-zero remainder.
    while ((guess % a > 0) || (guess % b > 0)) 
    {
	++guess;
    }
    return guess;
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
int gcd (int a, int b)
{
    // Look up Euclid's algorithm for computing gcd quickly!
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
int lcm_fast (int a, int b)
{
    // If you write gcd, then you can use gcd for a quick way of computing lcm!
}
//-----------------------------------------------------------------------------
