Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int calcdist(double ang, double vel)
- {
- double pi = 3.1415926535;
- double rad = 180 * pi;
- double radang = ang / rad;
- double yvel = sin(radang) * vel;
- double xvel = cos(radang) * vel;
- double y0 = 3.2;
- double y1 = 0;
- double time = vel / 9.8;
- time *= 2;
- double dist = (2 * xvel * yvel) / 9.8;
- return dist;
- }
- int calctime(double a, double v)
- {
- double pi = 3.1415926535;
- double rad = 180 * pi;
- double radang = a / rad;
- double time = v / 9.8;
- time *= 2;
- return time;
- }
- 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 || angle > 360)
- {
- 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 t = calctime(angle, velocity);
- double distance = calcdist(angle, velocity);
- cout << "The projectile will have travelled " << setprecision(20) << distance << "m taking " << setprecision(20) << t << "s.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement