Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "constants.h"
- using namespace std;
- using namespace myConstants;
- double getInitialHeight()
- {
- cout << "Enter initial height ";
- double initialHeight;
- cin >> initialHeight;
- return initialHeight;
- }
- double calculateHeight(double initialHeight, int seconds)
- {
- double distanceFallen = (gravity * seconds * seconds) / 2;
- double currentHeight = initialHeight - distanceFallen;
- return currentHeight;
- }
- void printHeight(double height, int seconds)
- {
- if (height > 0.0)
- {
- cout << "At " << seconds << " height is " << height << endl;
- }
- else
- {
- cout << "At " << seconds << " the ball is on the ground." << endl;
- }
- }
- void calculateAndPrintHeight(double initialHeight, int seconds)
- {
- double height = calculateHeight(initialHeight, seconds);
- printHeight(height, seconds);
- }
- void main()
- {
- const double initialHeight = getInitialHeight();
- int seconds = 0;
- int x;
- while (calculateHeight(initialHeight, seconds) > 0)
- {
- seconds++;
- calculateAndPrintHeight(initialHeight, seconds);
- }
- cout << "Type any button to exit \n";
- cin >> x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement