C++ problem with the effects of gravity
Jan 21, 2013 at 10:16pm UTC
Hi, I'm trying to write a code to display the results of gravity on an object being dropped from a certain height. The user inputs the tower's height and the output should be a table displaying the effects of gravity on the object for every second. Example( 0s, 1s, 2s... ect.)
This is what I have so far.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include<iostream>
using namespace std;
const double gravity=9.80665;
double height= tower_height - distance;
while(distance <= tower_height && distance >=0)
cout<< "Enter the height of the tower: "<<endl;
height = tower_height - distance;
cout<< "The height of the object at "<<time<< "/n is"<<height<< 'm'<<endl;
Jan 21, 2013 at 10:27pm UTC
2 3 4
double height= tower_height - distance; tower_height
contains some random value, and so does
is initialized by multiplying a constant times some random value and dividing by 2 which gives
... some random value.
is initialized by subtracting a random value from a random value.
Something tells me, our output is going to look random.
Do you really think you should be asking for input every iteration of the loop that's meant to display the table in question?
The loop condition depends on
is never updated within the loop.
Topic archived. No new replies allowed.