i need to write a fuction called fallingDistance that accepts an objects falling time as an argument. The fuction should return the distance, in meters, that the object has fallen during that time interval. write a program that demonstrates the function by calling it in a loop that passes the values 1 through 10 as arguments, and displays the return value. i'm at a lost on this one.
can anybody give me the basic skeleton of the program and i can go from there.
just tell me what comes before the int main() and if i need any #include besides <iostream>, also were do i put d=1/2gt^2. if i should put the loop after the int main() or near the end of the program.
Assuming u are using C++ d=1/2gt^2 is the same as d=1/2*g*t*t
If u use a for loop i=0;i<10;i++ and assign i to t successively ( t=i) then u should be able to print out d for values of t between 0<t<10.
The function fallingDistance() could include the for loop ,the formula and a cout>> statement. Const double g=32.2 or 980 should probably be declared globally above main(). About the only code in main() would be the function call. Have a go at it and post your code if u need help.
cout << "Giving the G and the T I will give you the D ";
cin >> d
return d;
}
double fallingDistance(double, double, double)
{
)
[code]
i got this so far i dont know if that right, if it is where do i put the for loop and the d=1/2gt^2. if its not right what do i need to change.
#include <iostream>
namespace std;
double fallingDistance()
constdouble = 32.2
int main ()
{
double d, g, t;
cout << "Giving the G and the T I will give you the D ";
cin >> d
return d;
}
double fallingDistance()
{
double g, t, d;
for (int i=0;i<10;i++)
int t =i+1,d;
d=0.5*g*t*t;
cout << d << " "; << endl;
}
here is the code let me know if it is alright or if i'm missing something.