Untitled
unknown
plain_text
4 years ago
955 B
6
Indexable
#include <iostream>
#include <string>
#include <iomanip>
constexpr double earthGravity{ 9.8 };
double getHeight()
{
std::cout << "Enter the height of the tower in meters : ";
double towerHeight{};
std::cin >> towerHeight;
return towerHeight;
}
double distanceFallen(double x, double y)
{
double distanceFallen{ y - (earthGravity*(x * x))/2.0 };
if (distanceFallen <= 0)
{
std::cout << "The ball is on the ground ";
}
else
{
std::cout << "The ball is at height " << (distanceFallen) << " meters after " << x << " seconds \n";
}
return 0;
}
int main()
{
const double heightEntered{ getHeight() };
for (double i = 0.0; i <= 5; i++)
{
distanceFallen(i, heightEntered);
//distanceFallen(1.0, heightEntered);
//distanceFallen(2.0, heightEntered);
//distanceFallen(3.0, heightEntered);
//distanceFallen(4.0, heightEntered);
//distanceFallen(5.0, heightEntered);
}
return 0;
}Editor is loading...