/*************************************************************
  File: main.cpp
  Name: CDR B. A. Osborn
  Class 16 function definition example
  Description: This program demonstrates how to declare and 
               define a function.  In this case, it is a
                          function which calculates and returns the 
                          max height of a projectile, given an initial
                          velocity and launch angle.
 ************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
 
// Function prototype
double height(double , double);
 
int main()
{
        double v, a, h;
        cout << "Enter velocity and angle: ";
        cin >> v >> a;
 
        h = height(v, a); // function call
        cout << h << endl;
 
        return 0;
}
 
 
/*********************************************
 function: height
 parameters:  double vel - initial velocity
              double angle - launch angle
 returns: double ht - max height
 
 Function definition which consists of the 
 return type  fcn name   parameters
   |          /          /     \
   |        /          /        \
   |      /          /           \             */
double height(double vel, double angle)
{
        double radians, ht;
        const double g = 9.8;
        const double PI = 3.1415926;
 
        radians = angle*PI/180.0;
 
        ht = pow((vel*sin(radians)),2.0)/(2.0*g);
 
        return ht;
}
 
 

syntax highlighted by Code2HTML, v. 0.9.1