Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

who can help me here

Status
Not open for further replies.

nylonelyguy

Technical User
Sep 9, 2003
7
US
using the sqrt() to determine the time it takes a ball to hit the ground after it has been dropped from 800 foot tower.
g=32.2 ft/sec^2
write a function to do that. please take it into consderation that im new to c++.

> Thank you

i think the formula for the time
time=sqrt(2*distance/g)
 
OK, so you say you are new to C++, how far have you got with your code, or even your ideas for the code ?
As far as I can see it it is pretty straight forwards !

Have you done any C++ coding yet ?

Is your code a console (DOS box) or a Windowed ap ?
And to be pedantic your formula for the distance dropped doesn't take into account wind resistance, the weight of the ball etc ! (but I'd guess that in this case it's the writing f the code that counts not the accuracy of the fn

K
 
thanx for the reply. well as i said im really new to c++. i did many simple programs though. i just started to learn function. im using visual c++ 6.

here what i have but i dont think it is right.
#include <iostream.h>
#include <math.h>
double time(double, double);

void main()
{
double t;
double dist= 800;
double g=32.2;
t=time(dist,g);

cout<<" The time it takes a ball to hit the ground is : "<<t;
}
double time(double dist, double g)
{

return sqrt(2*dist/g);

}

 
Seems OK here, except that main returns an int and not void

Describe what "doesn't seem right"

Perhaps you need to make the program pause to stop the console window from disappearing straight away.
Code:
int main()
{
    double t;
    double dist= 800;
    double g=32.2;
    t=time(dist,g);

    cout<<" The time it takes a ball to hit the ground is : "<<t<<endl;
    cin.get();
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top