Table isn't showing right.

When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period.
D = ½ gt^2

The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time in second that the object has been falling.
Write a function named fallingDistance that accepts an object’s falling time (in seconds) as an argument. The function 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 though 10 as arguments, and displays the return value.

When I run this, the seconds do go to 10.

But they do not do this under the seconds column like I need them to and the values for distance aren't showing up. They're also supposed to be like the seconds down in a row side by side under distance. What am I doing wrong?
1
2
3
4
5
6
7
8
9
10
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Ashton Dreiling
//Falling distance exercise
#include <iostream>
#include <stdlib.h>

//global constants
const int MAX_VALUE=10;
const double HALF=1/2;
const double NUM_FOR_CAL_IN_DISTANCE_FORMULA=9.8;
const int ZERO_FOR_CAL=0;

//module prototype
double fallingDistance(int);


using namespace std;

int main()
{
    //variable needed
    double distance;
    int seconds=0;

    //setting up table
    cout << "Seconds\t\t\tDistance" << endl;
    cout << "---------------------------------" << endl;


    for (seconds = ZERO_FOR_CAL;seconds<MAX_VALUE;++seconds);
{
        distance=fallingDistance(seconds);
        cout << seconds << "\t\t\t" << distance << endl;
    }
    return 0;
}//end main

double fallingDistance(int seconds)
{
    double D;
    D=(HALF*NUM_FOR_CAL_IN_DISTANCE_FORMULA * seconds*seconds);
    return D;
}
Have you tried printing out the values of those constants? If you do I would bet you will be surprised by the results.

What do you mean?
Last edited on
I mean try printing out those global constants you created.
I don't know what you mean when you say print.
You're kidding right? If you don't know how to print (display) your variables then maybe you should find some other hobby.

I know what printing is. I didn't understand what you meant at first.

Why print out my global constants? It's the table I want to work.
Last edited on
Why print out my global constants?

To check that they actually have the values that you want them to have.
Interesting.

Alright, well, it fixed the distance.

However, I'm still needing both the seconds and distance to display.

1.
2.
3.
4.
5.
etc and same with distance (but not ones the actual distance)

How do I fix that?
closed account (48T7M4Gy)
Show us a sample of what you get and a separate sample of what you expect please.
I fixed it, actually. I removed the semicolon at the end of ++seconds.
Topic archived. No new replies allowed.