-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfallDistance.cpp
31 lines (24 loc) · 953 Bytes
/
fallDistance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*********************************************************************
** Author: Jordan Hamilton
** Date: 01/31/2018
** Description: This function takes a double representing seconds
** as an argument, then calculates and returns the distance an object
** has fallen in the number of seconds specified.
*********************************************************************/
#include <cmath>
#include <iostream>
using namespace std;
double fallDistance(double seconds);
int main() {
double seconds;
cout << "Input a time in seconds an object has fallen, then press enter: ";
cin >> seconds;
cout << "That object fell " << fallDistance(seconds) << "m in " << seconds << " seconds." << endl;
return 0;
}
double fallDistance(double seconds) {
// Create a named constant for gravitational acceleration
double const ACCELERATION = 9.8;
// Return the distance traveled in meters
return 0.5 * ACCELERATION * pow(seconds, 2.0);
}