Patrick B. answered • 04/14/21

Math and computer tutor/teacher

/***************************************

_ H _ T _ P H Y S _ C S

would you like to buy a vowel???

--------------------------------------------

R = initial_velocity^2 * sin 90 / g

= initial_velocity^2 * 1/g

= initial_velocity^2/g

h = initial_velocity^2 * (sin45)^2/(2g)

= initial_velocity^2 * (sqrt(2)/2)^2 / (2g)

= initial_velocity^2 * (1/2) / (2g)

= initial_velocity^2 / (4g)

*********************************************************/

using namespace std;

#include <iostream>

#include <math.h>

#define PI (3.14159265359 )

#define GRAVITY (32.17405)

#define EPSILON (0.00001)

Go()

{

double d=-1;

double initial_velocity=-1;

double Range;

double Height;

double V02; //square of the initial velocity

while (d<=0)

{

cout << " Please input the distance from the wall :>";

cin >> d;

}

while (initial_velocity<=0)

{

cout << "Please input the initial velocity :>";

cin >> initial_velocity;

}

V02 = initial_velocity*initial_velocity;

Range = V02/GRAVITY;

Height = V02/(4*GRAVITY);

cout << "Range is " << Range << " : Height is " << Height << endl;

double maxRange = d+200;

double minRange = d+150;

if (Height>75) //max height clears the wall

{

if ((Range>=minRange) && (Range<=maxRange))

{

cout << "HIT" << endl;

}

else if (Range>maxRange)

{

cout << "too far" << endl;

}

else if ((Range<minRange) && (Range>=d))

{

cout << "Short" << endl;

}

}

else // max height does not clear the wall

{

if (abs(Range-d)<EPSILON)

{

cout << "Hit the wall" << endl;

}

else //did not even come close to the wall

{

cout << " not even close " << endl;

}

} //clears the wall?

}

int main()

{

Go();

}