Hey everyone I am trying to write a physics program where the user can enter the x and y coordinates and the x and y velocity and then the program will return the x and y coordinates when t = 1, 2, 3, and 4. So far I have got the program running already, but I am only allowed a maximum of 30 lines of code on each function. Here is part of the code that I think can be simplified.
double t = 0;
double x_acc = 0;
double x_pos = x_init + (x_vel_init * t) + 0.5 * (x_acc * t * t);
double y_acc = -9.81;
double y_pos = y_init + (y_vel_init * t) + 0.5 * (y_acc * t * t);
cout << "Position after 0 second(s) is (" << x_pos << "," << y_pos << ")" << "\n";
t = 1;
x_acc = 0;
x_pos = x_init + (x_vel_init * t) + 0.5 * (x_acc * t * t);
y_acc = -9.81;
y_pos = y_init + (y_vel_init * t) + 0.5 * (y_acc * t * t);
cout << "Position after 1 second(s) is (" << x_pos << "," << y_pos << ")" << "\n";
t = 2;
x_acc = 0;
x_pos = x_init + (x_vel_init * t) + 0.5 * (x_acc * t * t);
y_acc = -9.81;
y_pos = y_init + (y_vel_init * t) + 0.5 * (y_acc * t * t);
cout << "Position after 2 second(s) is (" << x_pos << "," << y_pos << ")" << "\n";
t = 3;
x_acc = 0;
x_pos = x_init + (x_vel_init * t) + 0.5 * (x_acc * t * t);
y_acc = -9.81;
y_pos = y_init + (y_vel_init * t) + 0.5 * (y_acc * t * t);
cout << "Position after 3 second(s) is (" << x_pos << "," << y_pos << ")" << "\n";
t = 4;
x_acc = 0;
x_pos = x_init + (x_vel_init * t) + 0.5 * (x_acc * t * t);
y_acc = -9.81;
y_pos = y_init + (y_vel_init * t) + 0.5 * (y_acc * t * t);
cout << "Position after 4 second(s) is (" << x_pos << "," << y_pos << ")" << "\n";
Any suggestions would be nice. Thanks!