#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
int main()
{
double a = 9.8; // units = meters
double radians;
double angle, velocity;
double vx, vy, x, y;
float time;
ofstream outfile("traj.out");
cout << "Enter velocity: ";
cin >> velocity;
cout << "Enter angle: ";
cin >> angle;
radians = angle*M_PI/180.0;
vx = velocity * cos(radians);
vy = velocity * sin(radians);
for(time=0; time < .5; time += .01)
{
x = vx * time;
y = vy * time - 0.5 * a * time * time;
cout << "Time: " << time << " x: " << x
<< " y: " << y << endl;
outfile << "Time: " << time << " x: " << x
<< " y: " << y << endl;
}
cout << "Vx = " << vx << " Vy = " << vy
<< " Veloc= " << velocity << " Angle= " << angle
<< " Rad= " << radians << endl;
outfile << "Vx = " << vx << " Vy = " << vy
<< " Veloc= " << velocity << " Angle= " << angle
<< " Rad= " << radians << endl;
outfile.close();
return 0;
}
syntax highlighted by Code2HTML, v. 0.9.1