here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
namespace std;

double fallingDistance()
const double = 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. i'm suppose to find the falling time of an object (in seconds) as an argument. i need to return the distance, in meters, that the object has fallen during the time interval. i need to demonstrate the fuction by calling it in a loop the passes the values 1 through 10 as arguments and displays the return value
closed account (z05DSL3A)
Have a look here:

http://www.cplusplus.com/forum/general/1073/

It should look familiar to you!
what about it. i'm sorry but i still don't understand. what am i missing.
closed account (z05DSL3A)
what about it.

Well, Xabnu was giving you help. If you did not understand it you should say in that thread not start another from exactly the same starting point.

here is the code let me know if it is alright or if i'm missing something
To answer your questions, No it is not alright, yes you are missing somthing. Xabnu has given you the answer if you don't understand it I sugest you go to the tutorial section and start reading.

http://www.cplusplus.com/doc/tutorial/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
#include <iostream>

#define GRAV = 32.2
double fallingDistance(double)

int main()
{
	   int i;
       double time,dist;
       for(i = 0; i < 10; i++)
   { 
     time = i + 1.0; 
     dist = fallingDistance(time);
     cout << "Given gravity of, " << GRAV << 
     " meters per second squared, an object will fall " 
	 << dist << " meters in " << time << " seconds." << endl;
	}
}
 double fallingDistance(double time)
{   
   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;
   return 0;
}

here is my new code, where exactly do i add my if statements. is there an easier way to do it using namespace function.
what do these errors mean:
Line 8 : error C2144: syntax error : 'int' should be preceded by ';'
Line 16 : error C2065: 'cout' : undeclared identifier
Line 16 : error C2059: syntax error : '='
Line 27 : error C2143: syntax error : missing ';' before '<<'
Last edited on
closed account (z05DSL3A)
I give...here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cmath>

const double GRAV = 9.80665; //  m/s/s
double fallingDistance(double);

int main()
{
    int i;
    double time,dist;
    std::cout << "Given gravity of, " << GRAV << " meters per second squared" << std::endl;
    for(i = 0; i < 10; i++)
    { 
        time = i + 1.0; 
        dist = fallingDistance(time);
        std::cout  << "After "  << time << " seconds, an object will fall " << dist << "meters." <<std::endl;
	}

    return 0;
}

double fallingDistance(double time)
{   
   return ((GRAV * pow(time,2)) /2);
}
Topic archived. No new replies allowed.