### C++ Class Assignment, Need Assistance ASAP

Ok, so my assignment is to write a program that computes how many feet an object falls in 1 second, 2 seconds, etc., up to 12 seconds. The formula is: d = ½ * g * t^2 (t squared), where g = 32.2.
This is what I have managed to do but the values for the distance are wrong on my program.

Values should be these:

Seconds Distance
================
1 16.1000
2 64.4000
3 144.9000
4 257.6000
5 402.5000
6 579.6000
7 788.9000
8 1030.4000
9 1304.1000
10 1610
11 1948.1000
12 2318.4000

It would be greatly appreciated if someone could tell me what went wrong and why as fast as you can. I am new to this programming stuff and have had some trouble with it. Thanks in advance.

 ``1234567891011121314151617181920212223242526272829303132`` ``````#include using namespace std; //Prototypes int FallingDistance(double distance); int fallingSeconds; int number; int main() { //Getting seconds cout << "Please enter the number of seconds" << endl; cin >> fallingSeconds; //Displaying the table cout << endl; cout << "Seconds Distance" << endl; cout << "====================" << endl; //For loop for (number = 1; number <= fallingSeconds; number++) cout << number << " " << FallingDistance << endl; return 0; } //FallingDistance function int FallingDistance(double distance) { distance = 1/2 * 32.2 * number * number; return distance; }``````
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/jEywvCM9/

2) In this line:

`cout << number << " " << FallingDistance << endl;`

... that is not how you call a function. The number you are outputting to cout is not the return value of the function. I recommend going back to your textbook and read up on how to call functions properly, because it's absolutely fundamental to C++ programming.
Last edited on
Topic archived. No new replies allowed.