Two (three? four?) things:
-- To call your
distance_formula, you need to put parentheses after the function name:
distance_formula()
-- I would change
distance_formula so that it returns the solution (as a
float
) instead of outputting the solution inside the function and then returning 0. Otherwise, you'll be outputting both the solution (inside the function, on line 17) and 0 (the return value, on line 33).
Also, global variables are generally frowned upon, so try to avoid using them when possible.
I would have written your code as
1 2 3 4 5 6 7 8 9 10 11 12 13
|
float distance_formula(float num1, float num2, float num3, float num4)
{
// ...
return solution;
}
int main()
{
float num1, num2, num3, num4;
// ...
cout << "The distance between these two pairs of numbers are: "
<< distance_formula(num1, num2, num3, num4) << endl;
}
|
On a side note, since this is C++, I would advise using
#include <cmath>
instead of
#include <math.h>
.
In this case, however, since you don't actually use any of the functions inside that header, you don't even need it at all. (Basic math operations like addition, subtraction, multiplication, division, and (integer) modulus are built-in operators -- you don't need to
#include
anything for those.)