Advertisement
Guest User

BallFall

a guest
Mar 5th, 2020
387
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include "constants.h"
  3.  
  4. using namespace std;
  5. using namespace myConstants;
  6.  
  7. double getInitialHeight()
  8. {
  9. cout << "Enter initial height ";
  10. double initialHeight;
  11. cin >> initialHeight;
  12. return initialHeight;
  13. }
  14.  
  15. double calculateHeight(double initialHeight, int seconds)
  16. {
  17. double distanceFallen = (gravity * seconds * seconds) / 2;
  18. double currentHeight = initialHeight - distanceFallen;
  19.  
  20. return currentHeight;
  21. }
  22.  
  23. void printHeight(double height, int seconds)
  24. {
  25. if (height > 0.0)
  26. {
  27. cout << "At " << seconds << " height is " << height << endl;
  28. }
  29. else
  30. {
  31. cout << "At " << seconds << " the ball is on the ground." << endl;
  32. }
  33.  
  34. }
  35.  
  36. void calculateAndPrintHeight(double initialHeight, int seconds)
  37. {
  38. double height = calculateHeight(initialHeight, seconds);
  39. printHeight(height, seconds);
  40. }
  41.  
  42. void main()
  43. {
  44. const double initialHeight = getInitialHeight();
  45. int seconds = 0;
  46. int x;
  47.  
  48. while (calculateHeight(initialHeight, seconds) > 0)
  49. {
  50. seconds++;
  51. calculateAndPrintHeight(initialHeight, seconds);
  52. }
  53.  
  54. cout << "Type any button to exit \n";
  55. cin >> x;
  56. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement