Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "constants.h"
- #include <iostream>
- double getHeight()
- {
- std::cout << "Enter starting height in meters: ";
- double x;
- std::cin >> x;
- return x;
- }
- bool onGround(double x)
- {
- if (x < 0)
- return true;
- else
- return false;
- }
- void calculate(double x, double y)
- {
- double initialHeight(x);
- int time(y);
- double distanceFallen;
- double currentHeight;
- currentHeight = initialHeight - (myConstants::gravity * (time * time)) / 2;
- if (onGround(currentHeight))
- std::cout << "At " << y << " seconds, the ball is on the ground.\n";
- else
- std::cout << "At " << y << " seconds, the ball is at height: " << currentHeight << '\n';
- }
- int main()
- {
- const double initialHeight = getHeight();
- calculate(initialHeight, 0);
- calculate(initialHeight, 1);
- calculate(initialHeight, 2);
- calculate(initialHeight, 3);
- calculate(initialHeight, 4);
- calculate(initialHeight, 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement