#include #include int main() { using namespace std; short reset=1; while (reset != 0) { double u=0, v=0, f, m, M, s=0, c=300000000, a=0, t, r=0, t0=0; double s0, custDest; short dest=10; cout << "Realistic physics space travel simulation\n"; cout << "Starting from Earth, where are you going?\n1 = Moon\n2 = Sun\n3 = Pluto\n4 = Proxima Centauri\n5 = Sirius\n"; cout << "6 = Custom distance in metres\n7 = Custom distance in light seconds\n8 = Custom distance in light years\n"; while (dest < 1 || dest > 8) { cin >> dest; if (dest == 1) {s0 = (384403000 / 2);} else if (dest == 2) {s0 = (149600000000 / 2);} else if (dest == 3) {s0 = (5913520000000 / 2);} else if (dest == 4) {s0 = 18900000000000000;} else if (dest == 5) {s0 = (81360000000000000 / 2);} else if (dest == 6) { cout << "\nEnter distance in metres:\n"; cin >> custDest; s0 = (custDest / 2); } else if (dest == 7) { cout << "\nEnter distance in light seconds:\n"; cin >> custDest; s0 = ( (custDest * 300000000) / 2); } else if (dest == 8) { cout << "\nEnter distance in light years:\n"; cin >> custDest; s0 = ( (custDest * 9460000000000000) / 2); } else {cout << "\nInvalid selection, please retry:\n";} } cout << "\nHow heavy is your ship in kg (100000kg is a good starting point)?\n"; cin >> m; cout << "\nAnd what force do your engines produce in N (1000000N is a good starting point)?\n"; cin >> f; cout << "\nAnd every how many seconds should I recalculate (1 is best for the greatest accuracy)?\n"; cin >> t; while (t <= 0) { cout << "\nRecalculation time must be nonzero and positive, please retry\n"; cin >> t; } cout << "\nBeginning simulation...\n"; while (s < s0) { if (u <= c) { M = ( m * ( c / ( sqrt( ( c * c ) - ( v * v ) ) ) ) ); a = ( f / M ); v = ( u + a * t ); } else { a = 0; u = c; v = u; } s = s + ( u * t + ( 0.5 * a * ( t * t ) ) ); u = v; t0 = t0 + t; r = r + t; if (r == 86400) { r = 0; cout << "day " << (t0 / 86400) << " | " << ((s * 100) / s0) << "% | " << (v / c) << "c\n"; } else if (r > 86400) { r = 0; cout << "second " << t0 << " | " << ((s * 100) / s0) << "% | " << (v / c) << "c\n"; } } cout << "Halfway point reached in "<< t0 << " seconds or " << (t0 / 86400) << " days or " << (t0 / 31557600) << " years\n"; cout << "Maximum velocity " << v << " ms^-1 or " << v/c << "c\n"; cout << "Arrival at destination: " << (t0 * 2) << " seconds or " << (t0 / 43200) << " days or " << (t0 / 15778800) << " years after departing Earth\n"; cout << "End of simulation\n"; cout << "Enter 1 to start over or 0 to quit\n"; cin >> reset; cout << "\n\n"; } return 0; }