Your first problem is you are printing out the result before you have gone to the function to calculate it, you need to call result = distanceTwo(xone, xtwo, yone, ytwo);
before your cout statements.
The second problem is you are setting a double 'r' in your function equal to an equation. Then you are returning the variable 'result' which hasn't been given a value at that point.
You will need to change it to
1 2 3
double r;
r = sqrt((pow((xone-xtwo),2))+(pow((yone-ytwo),2)));
return r;
Hey James,
thanks so much for your reply! I really appreciate it!
I made the given fixes to my code which when I think about it does make sense,
but unfortunately I still receive 0 for any type of number i put in when I run it.
here is the fixed version:
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
I should of been clearer when I said put your result before the cout statements. Seeing as C++ reads from top to bottom it needs to be placed after the user enters in xone/yone etc so that the function knows the values for those variables, but before you print out the final result.
1 2 3 4 5 6 7 8 9 10
cout << "Please enter the X and Y of the first point" << endl;
cin >> xone >> yone;
cout <<endl << "Please enter the X and Y of the second point" << endl;
cin >> xtwo >> ytwo;
result = distanceTwo(xone, xtwo, yone, ytwo);
cout <<endl << "the distance of " << xone << "," << yone << " and " << xtwo << ","
<< ytwo << " is " << result << "." << endl <<endl;