From c8e5b362094f2ffe7bee4f3fe10326556255a1bb Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 29 Jan 2024 17:14:22 +0100 Subject: [PATCH] second task --- src/main.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e8b148d..8fa3148 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include // for std::cout #include "io.h" +#include // Definition of function main() double get_user_double() @@ -38,15 +39,39 @@ void print_result(double a, double b, char c) } std::cout << a << ' ' << c << ' ' << b << " is " << result; } +void task1() +{ + double a{get_user_double()}; + double b{get_user_double()}; + char c{get_user_operator()}; + print_result(a, b, c); +} +long get_user_tower_height() +{ + std::cout << "Enter the height of the tower in meters: "; + long x{}; + std::cin >> x; + return x; +} +void task2() +{ + long tower_height{get_user_tower_height()}; + for (size_t i = 0; i < 6; i++) + { + double result{static_cast(tower_height) - 9.8 * pow(static_cast(i), 2) / 2}; + if (result <= 0.0) + std::cout << "At " << i << " seconds, the ball is on the ground\n"; + else + std::cout << "At " << i << " seconds, the ball is at height: " << result << " meters\n"; + } +} int main() { // add_two_numbers(); // convert_char_to_ascii(); // print_type_size_bytes(); - double a{get_user_double()}; - double b{get_user_double()}; - char c{get_user_operator()}; - print_result(a, b, c); + // task1(); + task2(); return 0; } \ No newline at end of file