Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "constants.h"
  3. #include <iostream>
  4.  
  5. double getHeight()
  6. {
  7.     std::cout << "Enter starting height in meters: ";
  8.     double x;
  9.     std::cin >> x;
  10.     return x;
  11. }
  12.  
  13. bool onGround(double x)
  14. {
  15.     if (x < 0)
  16.         return true;
  17.     else
  18.         return false;
  19. }
  20.  
  21. void calculate(double x, double y)
  22. {
  23.     double initialHeight(x);
  24.     int time(y);
  25.     double distanceFallen;
  26.     double currentHeight;
  27.  
  28.     currentHeight = initialHeight - (myConstants::gravity * (time * time)) / 2;
  29.  
  30.     if (onGround(currentHeight))
  31.         std::cout << "At " << y << " seconds, the ball is on the ground.\n";
  32.     else
  33.         std::cout << "At " << y << " seconds, the ball is at height: " << currentHeight << '\n';
  34. }
  35.  
  36. int main()
  37. {
  38.     const double initialHeight = getHeight();
  39.     calculate(initialHeight, 0);
  40.     calculate(initialHeight, 1);
  41.     calculate(initialHeight, 2);
  42.     calculate(initialHeight, 3);
  43.     calculate(initialHeight, 4);
  44.     calculate(initialHeight, 5);
  45.    
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement