Originally posted by Ganon11
Code:
#include <iostream.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
float const gravity = 9.8;
float velocity;
float seconds;
float 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/Seconds Squared)"<<'\n'<<'\n';
cout<<"Please enter the the launch velocity in meters/seconds squared."<<'\n';
cin>>velocity;
seconds=1;
height=0;
launch.setf(ios::showpoint||ios::fixed);
launch<<setprecision(2);
for(seconds=1;height >= 0;seconds++)
{
height = velocity * seconds - (1.0/2.0 * gravity * pow(seconds,2));
if (height<0)
launch<<setw(2)<<seconds<<setw(8)<<" "<<setw(10)<<0<<'\n';
else
launch<<setw(2)<<seconds<<setw(8)<<" "<<setw(10)<<height<<'\n';
}
launch.unsetf(ios::showpoint||ios::fixed);
launch.close();
system("PAUSE");
return 0;
}
Comment