Hey Everyone. I have a program for school that is suppose to project how many seconds it takes a projectile to hit the ground. I have the formula, but the loop is not posting to my output file. Can someone tell me what I'm doing wrong?
Code:
#include <iostream.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
float const gravity = 9.8;
double velocity;
double seconds;
double height;
ofstream launch;
int main()
{
launch.open("C:\\Documents and Settings\\All Users\\Desktop\\launch.dat");
launch<<setw(13)<<"Time(Seconds)"<<setw(8)<<" "<<setw(14)<<"Height(Meters)"<<'\n'<<'\n';
cout<<"Please enter the the launch velocity in meters/seconds squared."<<'\n';
cin>>velocity;
seconds = 1;
while(height > 0)
{
height = velocity * seconds - 1/2 * gravity * pow(seconds,2);
launch<<setw(13)<<seconds<<setw(8)<<" "<<setw(14)<<height<<'\n';
seconds++;
}
launch.close();
system("PAUSE");
return 0;
}
Comment