Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

Viewed less than a minute ago

7DNHfSwLtBxeO8WC

C++ gcc 12.1.0

Created at 1 minute ago

Created by anonymous

Author

anonymous

1 minute ago

Language

C++

Compiler

gcc 12.1.0

Options
Warnings
Don't Use Boost
C++11
-pedantic
セオライド・テクノロジー㈱株式会社フィックスターズ
Siv3D

Author

anonymous

1 minute ago

›
⌄
99
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
const double G = 6.67408e-11;

double r1, r2, m1, m2, x;
char burh;

cout << "Enter the mass and radius of sphere 1 (m1, r1): ";
cin >> m1 >> burh >>r1;
cout << "Enter the mass and radius of sphere 2 (m2, r2): ";
cin >> m2 >> burh >> r2;

while (m1 < 0 || r1 < 0 || m2 < 0 || r2 < 0) {
cout << "Error: Mass and radius values must be greater than zero, Please re-enter the values." << endl;
cout << "Enter the mass and radius of sphere 1 (m1, r1): ";
cin >> m1 >> burh >> r1;
cout << "Enter the mass and radius of sphere 2 (m2, r2): ";
cin >> m2 >> burh >> r2;
}

cout << "Enter the distance between the two spheres (x): ";
cin >> x;

while (x < 0) {
cout << "Error: Distance value must be greater than zero, Please re-enter the value." << endl;
cout << "Enter the distance between the two spheres (x): ";
cin >> x;
}

cout << "Distance (m)" << setw(20) << "Force (N)" << endl;

double d = x + r1 + r2;
double force = (m1 * m2 * G) / (d * d);
cout << fixed << setprecision(2) << setw(10) << d << setw(20) << force << endl;

for (int i = 1; i <= 20; i++) {
x -= x / 20;
d = x + r1 + r2;
force = (m1 * m2 * G) / (d * d);
cout << fixed << setprecision(2) << setw(10) << d << setw(20) << force << endl;
}

return 0;
}

›
9
1
2
3
4
1000000000,1
1000000000,1
1

$ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic
Enter the mass and radius of sphere 1 (m1, r1): Enter the mass and radius of sphere 2 (m2, r2): Enter the distance between the two spheres (x): Distance (m)           Force (N)
      3.00          7415644.44
      2.95          7669152.54
      2.90          7922220.96
      2.86          8174419.60
      2.81          8425331.03
      2.77          8674552.70
      2.74          8921698.95
      2.70          9166402.76
      2.66          9408317.27
      2.63          9647116.97
      2.60          9882498.77
      2.57         10114182.64
      2.54         10341912.20
      2.51         10565454.93
      2.49         10784602.24
      2.46         10999169.30
      2.44         11208994.74
      2.42         11413940.11
      2.40         11613889.30
      2.38         11808747.68
      2.36         11998441.31
Exit Code:
0
セオライド・テクノロジー㈱株式会社フィックスターズ
Siv3D