Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int calcdist(double ang, double vel)
- {
- double pi = 3.1415926535;
- double rad = 360 / (2 * pi);
- double radang = ang / rad;
- double yvel = sin(radang) * vel;
- double xvel = cos(radang) * vel;
- double y0 = 3.2;
- double y1 = 0;
- double half = 1 / 2;
- double time = ((y0 - y1 - yvel) / pow(((1 / 2) * -9.8), half));
- double dist = xvel * time;
- return dist;
- }
- int main()
- {
- double angle, velocity;
- cout << "Welcome to Projectile Shot Distance Calculator(Note: this program will assume the projectile is fired from a 3.2m high tank)!\n";
- cout << "The answer will be in m.\n";
- cout << "Enter the angle the projectile is fired at(in degrees): " << endl;
- cin >> angle;
- cout << "Enter the velocity the projectile is fired at(in m/s): " << endl;
- cin >> velocity;
- if(angle < 0)
- {
- cout << "Angle cannot be negative!" << endl;
- cout << "Terminating program..." << endl;
- return 0;
- }
- if(velocity < 0)
- {
- cout << "Velocity cannot be negative!" << endl;
- cout << "Terminating program..." << endl;
- return 0;
- }
- double distance = calcdist(angle, velocity);
- cout << "The projectile will have travelled " << distance << "m.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement