Advertisement
Guest User

Untitled

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