#include #include #include using namespace std; int main() { double t, dt; double ts, y0, v0; int nsteps; string filename; cout << "Input initial position (y0):" << endl; cin >> y0; cout << "Input initial velocity:" << endl; cin >> v0; cout << "Input step (dt):" << endl; cin >> dt; // cout << "Input number of steps:" << endl; // cin >> nsteps; // Alternatively: double tmax; cout << "Maximum time (tmax):" << endl; cin >> tmax; nsteps = int(tmax/dt); cout << "Input File name: "<< endl; cin >> filename; //////////////////////////////////////////////////// double v = v0, y = y0; double g = -9.8; ofstream fout; fout.open(filename.c_str()); if(!fout) { cout << "Error: Unable to open file" << endl; exit(-1); } for(int n = 1; n <= nsteps; n++){ v += g*dt; // v = v + g * dt y += v*dt; // y = y + v * dt fout << n*dt << " " << y << " " << v << endl; } fout.close(); return 0; }