Golf ball

Hi, I need to write a program that calculates the distance of a golf ball dropped from an airplane in t seconds; The program displays the distance fallen in each second interval for 10 seconds and the total distance the golf ball falls at the end of each interval.
This is my code

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
int main ()


{
//A golf ball dropped from an airplane.

double const Gravity = 32;
double distance, time, totDistance;

//Gravity in ft/s^2.


time = 0;
totDistance =0;

cout << "Time Distance in current Time Total Distance " << endl;

while ( time < 10 )
{
distance = (.5) * Gravity * pow(time, 2);
time ++;
totDistance += distance;


cout << setw(3) << time << setw (20) << distance << setw(20) << totDistance << endl;

}

return 0;
}



I dont' know how to make the time to start form zero, i tried making time = -1, but i does not work because it will give me a negative distance. I would appreciate any help; Thanks
I wonder if the guys finished the physics library yet... Man I wish I didn't bail on that project.

Your "time" variable is starting at 0, I know this because you set it to 0. You are incrementing it before you display it though. You should move your 'cout' statement higher in the loop.
closed account (D80DSL3A)
You're kind of close but there is confusion.
Let totDistance = how far ball has fallen since release from plane.
Let distance = how far ball has fallen in the last second. Initialize to 0 (you don't presently).
Your formula gives totDistance so try this in your loop:
1
2
totDistance = 0.5*Gravity*time*time;// I wouldn't use pow() just to square - but you can.
distance = totDistance - distance;// subtracting last distance from new distance = difference 
Thanks, It makes now. I really appreciate your help.
Topic archived. No new replies allowed.