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:
You should first compute the product and then divide the result by 2 (The reason for this will be discussed later in the book).
#include<iostream>
using namespace std;
#define ACCELERATION 32
int main()
{
//Variables
int time;
double distance;
//User input
cout<<" Enter time(Seconds):";
cin>>time;
//Compute distance using the formula:
//distance=(acceleration*time^2)/2
distance = ((ACCELERATION * time *time)/2);
//Print output
cout<<"Traveled distance:" << distance <<"\n";
}
Output of code:
Enter time(Seconds):15
Traveled distance:3600