I am having a hard time passing arguments. The function fallingDistance is supposed to acquire a value for the variable time from the function seconds from 1-10 seconds. Function main is supposed to call function seconds 10 times. However the output of my program is "The distance is 0" ten times it does not do the calculations I want it to. What am I doing wrong?
The (1/2) does integer division and evaluates to 0. If you want FP arithmetic write (1.0/2.0)
Also, the pow function is very expensive for squaring numbers (it uses a series to calc the answer) , so just do (time * time) . Only use the pow function when the second arg isn't a whole number, as in pow(time, 1.2) , say.
You probably don't need 2 functions for this, can you figure out how to do it with 1 function.
A final point, avoid using magic numbers like 10 and 9.8 in your code - prefer to make them const variables, then refer to them by the variable name:
1 2 3 4 5 6 7
constunsignedint MaxTime = 10;
constdouble Gravity = 9.8;
for (int Time = 1; Time < MaxTime + 1; ++Time) { // always use braces even if 1 statement
FallingDistance(Time, Gravity);
}
(1/2) is an integer expression, which will always be zero. It doesn't matter what the rest of the expression is, the result will always be zero.
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.