C++ function help

Hey guys so i'm trying to figure out why my code is returning all 0's for distance 'd'? I ran through the 'step over' tool and it seems like it's not even entering my function? It just outputs 0 for everything. Thanks guys


#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;

double fallingDistance(int);

int main()
{
double d = 0;

for (int i = 1; i <= 10; i++) {


d = fallingDistance(i);

cout << i << " Seconds " << "Distance " << d << endl;
}
return 0;
}

double fallingDistance(int t)
{
double d = 0;
const double g = 9.8;

d = (1 / 2 * g) * pow(t, 2);

return d;

}
d = (1 / 2 * g) * pow(t, 2);

Try replacing 1/2 with 1.0/2.0.

1/2 is integer division which results in a value of 0.
OMG that explains everything. It worked! I was so confused. Thank you very much
Topic archived. No new replies allowed.