Loop

Need help fixing my loop. My program is due at 11.30 tonight so I need to finish it. Been working on it for a long time, but can't get the loop working.

I need it to create a table that shows:

Height     Time
  0.0         0
  55.1        1
 ... and so fourth

The program is able to compile and run, but just not how it is supposed to.
I am trying to have it create a table that lists all of the seconds from when the initial height is 0 and the ending height is 0.



My program so far:

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
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
using namespace std;


const double g = 9.8;

int main()
{
ofstream outfil("results.txt", ios::out);
double launchvelocity, lv;
int time, t;
float height, h;


cout << "Enter speed of launch velocity(m/s)   => ";
cin >> lv;

h = 0;
t = 1;
do {

        h = ((lv * t) - (.5 * g *(t * t)));
        ++t;
outfil << "Height= " << h << "Time=   " << t << endl;
cout << outfil << endl;
} while (h >= 0.0);

if (h < 0.0)
        return  h = 0;




outfil.close();

return 0;
}
Last edited on
line 29&30: no need to return anything, some pointers,

1. the pseudocode would be: if the value of h is less than zero, then make the value of h zero

2. you'd need to change the value of h inside the loop, but before you output it or display it

3. dude, change the thread title, no need to mention names. I didn't respond earlier because you're already close to figuring this out by yourself :)
Last edited on
Thanks for the help. Just needed help fast and since you guys have helped me a lot before I was trying to get your attention. But I already had to turn my program in, but thanks for helping. I was close to figuring it out, but just couldn't get it just right. But oh well.
I was close to figuring it out, but just couldn't get it just right. But oh well.

If I were a lecturer I'd rather receive an original but flawed solution than get a perfect but obviously copied submission from my students.
And if I were you, I'd use this as an excuse to set a meeting with the teacher and get his/her opinion on my codes.
Topic archived. No new replies allowed.