Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int calcdist(double ang, double vel)
  8. {
  9. double pi = 3.1415926535;
  10. double rad = 180 * pi;
  11. double radang = ang / rad;
  12. double yvel = sin(radang) * vel;
  13. double xvel = cos(radang) * vel;
  14. double y0 = 3.2;
  15. double y1 = 0;
  16. double time = vel / 9.8;
  17. time *= 2;
  18. double dist = (2 * xvel * yvel) / 9.8;
  19. return dist;
  20. }
  21. int calctime(double a, double v)
  22. {
  23. double pi = 3.1415926535;
  24. double rad = 180 * pi;
  25. double radang = a / rad;
  26. double time = v / 9.8;
  27. time *= 2;
  28. return time;
  29. }
  30. int main()
  31. {
  32. double angle, velocity;
  33.  
  34. cout << "Welcome to Projectile Shot Distance Calculator(Note: this program will assume the projectile is fired from a 3.2m high tank)!\n";
  35. cout << "The answer will be in m.\n";
  36. cout << "Enter the angle the projectile is fired at(in degrees): " << endl;
  37. cin >> angle;
  38. cout << "Enter the velocity the projectile is fired at(in m/s): " << endl;
  39. cin >> velocity;
  40.  
  41. if(angle < 0 || angle > 360)
  42. {
  43. cout << "Angle cannot be negative!" << endl;
  44. cout << "Terminating program..." << endl;
  45. return 0;
  46. }
  47. if(velocity < 0)
  48. {
  49. cout << "Velocity cannot be negative!" << endl;
  50. cout << "Terminating program..." << endl;
  51. return 0;
  52. }
  53.  
  54. double t = calctime(angle, velocity);
  55.  
  56. double distance = calcdist(angle, velocity);
  57.  
  58. cout << "The projectile will have travelled " << setprecision(20) << distance << "m taking " << setprecision(20) << t << "s.\n";
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement