-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGravityTimeDilation.cpp
More file actions
39 lines (30 loc) · 912 Bytes
/
Copy pathGravityTimeDilation.cpp
File metadata and controls
39 lines (30 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <cmath>
using namespace std;
double TFAR(double TIS, double G, double M, double R){
double c = 3.0 * pow(10, 8);
double TOE = TIS * sqrt(1.0 - (2.0 * G * M) / (R * pow(c, 2)));
return TOE;
}
int main(){
double tis;
double g;
double m;
double r;
double c = 3.0 * pow(10, 8);
cout << "Enter time spent in space: ";
cin >> tis;
cout << "Enter gravitational constant: ";
cin >> g;
cout << "Enter mass of the gravitational source: ";
cin >> m;
cout << "Enter distance away from source center: ";
cin >> r;
if ((2.0 * g * m) / r >= pow(c, 2)) {
std::cerr << "Error: The coordinates put you inside or at a black hole event horizon" << std::endl;
return 1;
}
double timeD = TFAR(tis, g, m, r);
cout << "Time elapsed on Earth: " << timeD << " seconds" << std::endl;
return 0;
}