### help. having trouble converting c to c++

#include <stdio.h>
#include <string.h>
#include <math.h>

#define r 1e+3
#define m0 100e+3
#define g 9.81

main()
{
double m();
double p();
double k;
double dt=1;
double t;
double T;
double x0,x1,x2;

T=1.1*m0*g;

k=m0*g/1000;

x0=0;
x1=1;

printf("0.0000 %f\n", x0);
printf("%f %f\n", dt, x1);

for (t=dt; t<90; t+=dt)
{
x2=(4*m(t)*x1-(2*m(t)-dt*(-r+k*p(x1)))*x0-2*dt*(m(t)*g-T))/(2*m(t)+dt*(-r+k*p(x1)));
x0=x1
x1=x2

print f("%f %f\n", t+dt, x2);
}
}

float m(t)
float t;
{
return(m0-r*t);
}

float p(x)
float x;
{
return(exp(-x/1000));
}

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include #include #include #define r 1e+3 #define m0 100e+3 #define g 9.81 double m(float); double p(float); int main() { double k; double dt=1; double t; double T; double x0,x1,x2; T=1.1*m0*g; k=m0*g/1000; x0=0; x1=1; printf("0.0000 %f\n", x0); printf("%f %f\n", dt, x1); for (t=dt; t<90; t+=dt) { x2=(4*m(t)*x1-(2*m(t)-dt*(-r+k*p(x1)))*x0-2*dt*(m(t)*g-T))/(2*m(t)+dt*(-r+k*p(x1))); x0=x1; x1=x2; printf("%f %f\n", t+dt, x2); } return 0; } double m(float t) { return(m0-r*t); } double p(float x) { return(exp(-x/1000)); } ``````

What does it calculate?
thank you. it calculates rocket launch trajectory
Topic archived. No new replies allowed.