SomeOneHackedMyName (17) Mar 19, 2010 at 1:58am UTC
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...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include <iostream>
#include <cmath>
#include <cstdlib>
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 Mar 19, 2010 at 1:58am UTC
firedraco (2607) Mar 19, 2010 at 1:58am UTC
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.
demosthenes2k8 (161) Mar 19, 2010 at 1:58am UTC
You could probably just make a single function that does the entire formula...and takes four floats as parameters...and returns a float.
firedraco (2607) Mar 19, 2010 at 1:58am UTC
^Yes.
janek566 (7) Mar 19, 2010 at 1:58am UTC
^Yes
demosthenes2k8 (161) Mar 19, 2010 at 1:58am UTC
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))
This topic is archived - New replies not allowed.