### Distance Formula Not Homework

I'm not a C++ student, I'm self taught 14, and I wanted to make a program to solve my Geometry :p, like you've never tried.
So help soon would be greatly appreciated before the section is over.

My compiler (Dev-C++) says the following error: "too few arguments to function `float DistanceCalc(float, float)'"
What is wrong. I'm trying to have the user input xone, xtwo, yone, and ytwo (x1, x2, y1, and y2 respectively). Then the functions take care of the rest (squaring, powering, adding, and subtracting), but the program hits the error when it comes to the simple addition...
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` ``````#include #include #include using namespace std; /*X1*/ float xone; /*X2*/ float xtwo; /*Y1*/ float yone; /*X2*/ float ytwo; /*XTOTAL*/ float xtotal; /*YTOTAL*/ float ytotal; /*XPOW*/ float xpow; /*YPOW*/ float ypow; /*XSQRT*/ float xsqrt; /*YSQRT*/ float ysqrt; /*DISTANCE*/ float Distance; float xtotalCalc(float xone, float xtwo){ xtotal = xtwo - xone; return (xtotal);} float ytotalCalc(float yone, float ytwo){ ytotal = ytwo - yone; return (ytotal);} float xpowCalc(float xtotal){ xpow = xtotal * xtotal; return (xpow);} float ypowCalc(float ytotal){ ypow = ytotal * ytotal; return (ypow);} float xsqrtCalc(float xpow){ xsqrt = sqrt(xpow); return (xsqrt);} float ysqrtCalc(float ypow){ ysqrt = sqrt(ypow); return (ysqrt);} float DistanceCalc(float xsqrt, float ysqrt){ // <---------- Error Distance = xsqrt + ysqrt; return (Distance);} int main(int argc, char *argv[]) { cout << "Get started." << endl; cout << "What are the following points: " << endl; cout << "x1: "; cin >> xone; cout << endl << "x2: "; cin >> xtwo; cout << endl << "y1: "; cin >> yone; cout << endl << "y2: "; cin >> ytwo; cout << endl; cout << "The distance to your problem is: " << DistanceCalc(Distance) << endl; cin.ignore(); return EXIT_SUCCESS; }``````

Go to PurpleMath.com to see the formula: http://www.purplemath.com/modules/distform.htm
Last edited on
You have way too many functions for what you are trying to do...(Style hint: Don't put braces on the same line as the last line of the function).

The problem is you are calling DistanceCalc() on line 62 with only one parameter, but your definition says it takes 2.
You could probably just make a single function that does the entire formula...and takes four floats as parameters...and returns a float.
^Yes.
^Yes
To answer your actual problem, you're not calling any of the other functions before, so those global variables just have junk data in them.

Also, you're doing the formula wrong. It's not
`(sqrt(pow(x2-x1),2)+(sqrt(pow(y2-y1),2)`
It's:
`sqrt(pow(x2-x1),2)+pow(y2-y1),2))`
Topic archived. No new replies allowed.