// Nicolas Ruano                   CS1A                   Chapter 6, P. 370, #5
/******************************************************************************
* FUNCTION SOLVES FALLING OBJECT DISTANCE FOR 1 TO 10 SECONDS. 
 
* _____________________________________________________________ 
 
* Program Function computes how far an object falls under 
 
* gravity between 1 and 10 seconds using this formula: 
 
* Computation is based on the formula: 
 
* 
 
* d = 1/2 * g * t^2 
 
* 
 
* Where: 
 
*       d = distance in meters 
 
*       g = acceleration due to gravity (9.8 m/s²) 
 
*       t = time in seconds 
 
* ____________________________________________________________ 
 
* INPUT 
 
*   t -> int    Time (seconds) 
 
* 
 
* 
 
* OUTPUT 
 
*   d -> double    Distance fallen (meters). 
 
*******************************************************************************/ 
 
 
 
#include <iostream>   // Needed for input and output 
 
using namespace std; 
 
 
 
// Function to calculate falling distance 
 
double fallingDistance(int t) { 
 
    const double g = 9.8;          // Acceleration due to gravity (m/s^2) 
 
    double d = 0.5 * g * t * t;    // d = 1/2 * g * t^2 
 
    return d; 
 
} 
 
 
 
int main() { 
 
    cout << "Time (s)\tDistance (m)\n"; 
 
    cout << "---------------------------\n"; 
 
 
 
    // Loop through time values from 1 to 10 seconds 
 
    for (int time = 1; time <= 10; time++) { 
 
        double distance = fallingDistance(time); 
 
        cout << time << "\t\t" << distance << endl; 
 
    } 
 
 
 
    return 0; 
 
}