Problem with function returning correct value

Confused here, what is wrong with my syntax?

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>
#include <cmath>

using namespace std;

double fallingDistance(double time)
{
	
	double distance;
	const double gravity = 9.8;
	distance = 1/2 * gravity * time * time;
	return distance;
}

int main()
{
	double trueDistance;
	double time;
	cout << "Welcome to the distance calculation program!" << endl;
	cout << "Please enter a falling time for object in seconds" << endl;
	cin >> time;
	cout << "The distance the object fell is" << endl;
	trueDistance = fallingDistance(time);
	cout << trueDistance;
	return 0;
}

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
  #include <iostream>
#include <cmath>

using namespace std;

double fallingDistance(double time)
{
	
	double distance;
	const double gravity = 9.8;
	distance = (gravity * time * time)/2; //updated your syntax here, easier to read and runs fine.
	return distance;
}

int main()
{
	double trueDistance;
	double time;
	cout << "Welcome to the distance calculation program!" << endl;
	cout << "Please enter a falling time for object in seconds" << endl;
	cin >> time;
	cout << "The distance the object fell is" << endl;
	trueDistance = fallingDistance(time);
	cout << trueDistance;
	return 0;
}
thanks
Topic archived. No new replies allowed.