-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (40 loc) · 1.3 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (40 loc) · 1.3 KB
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
#include <iostream>
#include <windows.h>
#include <iomanip>
struct SimulationResult {
double totaltime{0.0};
double VelocityY{0.0};
};
SimulationResult FreeFall (double StartHeight, double Gravity) {
double PositionY = StartHeight;
double VelocityY = 0.0;
double deltatime = 0.1;
double totaltime = 0;
std::cout<<std::fixed<<" Time | Height | Velocity\n";
while (PositionY > 0) {
VelocityY = VelocityY + (deltatime * Gravity);
PositionY = PositionY + (VelocityY * deltatime);
totaltime = totaltime + deltatime;
if (PositionY < 0) {
PositionY = 0;
}
std::cout<<std::fixed<<" "<<totaltime<<" | "<<PositionY<<" | "<<VelocityY<<"\n";
Sleep(100);
}
SimulationResult result;
result.totaltime = totaltime;
result.VelocityY = VelocityY;
return result;
}
int main() {
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
double StartHeight = 100;
double Gravity = -9.8;
SimulationResult data = FreeFall(StartHeight, Gravity);
std::cout<<"Total time to fall:"<<data.totaltime<<"\n";
std::cout<<"Total velocity:"<<data.VelocityY<<"\n";
std::cout<<"\nPress Enter to exit:";
std::cin.get();
return 0;
}