Fumction not calculating correctly.(-16*time) ^2+initlal velocity+height.

#include<iostream>
#include <cmath>

using namespace std;


double VelocityCalculation(double initialVelocity, double time)
{


const double GRAVITY = -32.0;
return GRAVITY*time + initialVelocity;
}
double PositonCalculation ( double square,double startVELOCITY,double time, double tall)
{
const double Position_EQUATION = -16;

return exp(Position_EQUATION * square)+ (startVELOCITY * time) + tall;
}
int main()
{

const double POSITIVE_HEIGHT = 1000;
const double VELOCITY_LIMIT = -500;
const double VEL_ADD =500;


double height;
double velocity;
double velocity_answer;
double position_answer;
double moment;
double new_position;
double Squared;


cout << endl;
cout <<" Program will calculate the position and velocity of a falling object. ";
cout << endl << endl <<endl;
cout <<" Enter the initial height in feet (above 1000): ";
cin >> height;
cout << endl;

while ( height < POSITIVE_HEIGHT )

{ cout << " Invalid answer. Must enter height over 1000:" << endl;
cout << " Enter the initial height in feet (above 1000): ";
cin >> height;
cout << endl; }

cout <<" Enter the intial velocity in ft/sec: ";
cin >> velocity;
cout << endl;

cout <<"Enter the time: ";
cin >> moment;

while ( velocity < VELOCITY_LIMIT )

{ cout << " Invalid answer. Must enter velocity over -500:" << endl;
cout << " Enter the velocity above -500): ";
cin >> velocity;
cout << endl; }


velocity_answer = VelocityCalculation (velocity,moment);
if(velocity_answer> VELOCITY_LIMIT)
cout << velocity_answer<<endl;
else
{velocity_answer == VELOCITY_LIMIT;}

position_answer = PositonCalculation ( moment,velocity,moment,height);
if( velocity_answer> VELOCITY_LIMIT)
cout<< position_answer;
else if(velocity_answer<= VELOCITY_LIMIT)
{position_answer=position_answer - VEL_ADD;
cout <<position_answer<<endl;
cout<<VELOCITY_LIMIT;}





cout<<endl<<endl;
cout << " Press [enter] to exit" <<endl;
cin.ignore(); //needed because of keyboard input
cin.get();
return 0;
}
return exp(Position_EQUATION * square)+ (startVELOCITY * time) + tall;
exp() doesn't return the square of the parameter, it returns e raised to the power of the parameter. To square a number, use pow(x,2) or x*x, which is faster.
Also, I think your formula is wrong. After t time with g gravity, an object starting at v velocity and h height will be at a height of -.5gt2+vt+h.
It's important to note that -.5gt2 is the same as -.5g(t2), not (-.5gt)2.
Last edited on
Topic archived. No new replies allowed.