This is the code for my first CS1 project, I hope to be posting my code here to track my progress of learning the language of C++. I shouldn't be too shabby, since I know C considerably well and have reviewed C++ code here before.
Write a program that allows the user to enter a time in seconds and then outputs how far an object would drop if it is in freefall for that length of time. Assume that the object starts at rest, there is no friction or resistance from air, and there is a constant acceleration of 32 feet per second due to gravity. Use the equation:
$$ \text{distance} = \dfrac{\text{acceleration} \cdot\text{time}^2}{2} $$
rock.cpp
:
/**
* @file rock.cpp
* @brief Determines the height that a rock falls (in feet) after a given time
* @author syb0rg
* @date 9/8/14
*/
#include <iostream>
#include <cmath>
int main(void)
{
// initialize variables on declaration
double time = 0;
double acceleration = 32.174;
std::cout << "Enter the time in seconds that a rock will fall: ";
std::cin >> time;
double feetFallen = (acceleration * pow(time, 2)) / 2;
std::cout << "The rock fell " << feetFallen << " feet." << std::endl;
}