Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string.h>
- #include <limits.h>
- #include <iomanip>
- using namespace std;
- const double gravity = 9.8;
- int main()
- {
- //Declaration
- {
- double angleDeg = 0.0, v = 0.0, angleRad = 0.0, R = 0.0, x = 0.0, y = 0.0, T = 0.0, t = 0.0, i;// v = velocity
- bool done = false;
- //input
- cout <<"What's the angle?" <<endl;
- cin >> angleDeg;
- while (angleDeg < 0 || angleDeg > 90){ // between 0 to 90
- cout << "Between 0~90 angle please :)" << endl;
- while(!(cin >> angleDeg)) // Loops that goes on until cin fails
- {
- cin.clear(); // if fails, clear the failed flag.
- while(cin.get() != '\n'){} // A loop the cleans out anything that is left over in the input stream.
- cout << "Only numbers please: " << endl << "What's the angle again?" <<endl;// Output failed prompt. And requires only numbers
- }
- }
- cout << "Velocity?" <<endl;
- cin >> v;
- while (v < 0){ // between 0 to 90
- cout << "You know you can't go negative.. :)" << endl;
- while(!(cin >> v)) // Loops that goes on until cin fails
- {
- cin.clear(); // Clears cin if fails
- while(cin.get() != '\n'){} // A loop the cleans out anything that is left over in the input.
- cout << "Only numbers please: " << endl << "What's the velocity again?" <<endl;// Output failed prompt. And requires only numbers
- }
- }
- //processing
- angleRad = angleDeg*M_PI/180.0;
- R = (pow(v, 2.0)/gravity)*sin(2.0*angleRad); // = (v^2/g)sin(2x) Trajectory formula (googled the right formula..)
- T = (2.0*v*sin(angleRad))/gravity; // Total time
- x = (v*cos(angleRad)); // x coordinate
- y = (v*sin(angleRad)); // y coordinate
- {
- //output
- cout << "Your total distance: " << R << "meters" << endl << endl;
- cout << "Your travel time is: " << T << "s" << endl << endl;
- cout << "Max X coordinate: " << x << "meters" << endl << endl;
- cout << "Max Y coordinate: " << y << "meters" << endl << endl;
- }
- cout << "Distance" << endl;
- cout << "----------" << endl;
- double a = R/20;
- double b = x/20; //Declaring doubles
- double c = y/20;
- for (double i = R/20; i <= R; i = i + a)// Diving total distance by 20 and finding point
- { // Which start with distance1/20 ~ distance20/20
- cout << i << endl;
- }
- cout << endl << "X-Coordinates";
- cout << endl << "--------------" << endl;
- for (double o = x/20; o <= x/2; o = o + b) // Incrementing the X Vector.
- {
- cout << o << endl;
- }
- for (double o = x/2; o > x/21; o = o - b) // Decrementing the X Vector.
- {
- cout << o << endl;
- }
- cout << endl << "Y-Coordinates";
- cout << endl << "--------------" << endl;
- for (double p = y/20; p <= y/2; p = p + c) // Incrementing the Y Vector.
- {
- cout << p << endl;
- }
- for (double p = y/2; p > y/21; p = p - c)// Decrementing the Y vector.
- {
- cout << p << endl;
- }
- cout<< endl << "Thank you for using the program!" << endl;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment