I have been trying for a while to figure out how to put my program together where it writes to a file the height of a projectile.
The exact problem is stated as this: Write a program that writes to a file a table that shows the height of a projectile launched straight up for each second from launch time (time zero) until the projectile hits the ground. The last entry in the table should show a projectile height of 0. The height after t seconds is given by: s = (in. velocity)* t - .5gt^2 where g is 9.8m/s^2.
The program should prompt the user for the launch velocity.
I am trying to have it look like this table:
Height Time
0.0 0
55.1 1
... and so fourth
I understand that I need a loop in my program, but I am not sure how to create it where it depends on what value you input in for launch velocity. Like if you input 60, it shows seconds and heights for something like 16 second intervals. But if you input another number for launch velocity, you receive more or less table data for heights and time.
So in my case, I need height to show only positive integers based on my initial velocity input. I am just lost on how to correlate these things into a loop that writes it to a file since I have two random variables in time and height that correlate of each other.
Ok. I added the do-while loop into it, but in my table.txt file that it outputs the data to, I only get one set of data which is: when i input 60 for initial velocity
height =0 Time =14
I am not sure how to make it fill out a whole table like I wanted in my original post. Can someone explain to me what I need to add or change to my program.
well, thats because you just write the values once.
if you want to write all the value pairs, you have to put the outfil << ... stuff back in the loop (as you had before). and put the if-statement in it too, because you can have negative h if you dont check in the loop.
i was just giving an example how to make a working loop, leaving the rest to you ;)
btw, why do you declare launchvelocity, time, height? dont declare variables you dont use
I don't really understand when you say that I just write the values once, any way you can explain further. I understand that I should not declare the other variables and that I need to put the outfil << stuff back into the loop, but I am just confused on what to write into the loop so that it calculates the height at certain second intervals when you input an initial velocity and outputs the data into a txt file. Man am I confused
I fixed the outfil part, so it creates a table in a txt file like it is supposed to. But now I don't know how to fix my loop so that it outputs the right numbers. It is outputted the correct set, but the numbers are off. It should be