-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion_2_partD
44 lines (34 loc) · 906 Bytes
/
Question_2_partD
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
# include <iostream>
using namespace std;
double readDouble(){
printf("Enter the initial height of the tower in meters: ");
double x;
std::cin >>x;
return x;
}
void print_result(int q, double height){
if (height > 0){
std::cout << "At " << q << " seconds, the ball is at height: " << height << "\n";
}
else {
std::cout << "At " << q << " seconds, the ball on the ground \n";
}
}
double current_height(int time, double height){
const double gravity {9.8};
return height - (gravity*time*time*0.5);
}
int main(){
double q;
q = readDouble();
int time;
time = 0;
double height;
while ((current_height(time, q))>0){
height = current_height(time, q);
print_result(time, height);
time = time +1;
}
height = current_height(time, q);
print_result(time, height);
}