Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to write that calculates a distance between 2 points. However i get the error :
error: too few arguments to function ‘getDistance’


I tried debugging and I just cant figure out what is missing there.

What I have tried:

C++
#include <stdio.h>
#include <math.h>

typedef struct Point{
    double x, y;
} Point;

void printPoint(Point p){
    printf("x = %.1lf, y = %.1lf", p.x, p.y);
}

Point createpoint(double x, double y){
    Point p;
    p.x = x, p.y = y;
    return p;
}

double getDistance(Point a, Point b){
    return sqrt(pow((a.x-b.x), 2) + pow((a.y-b.y), 2));
}
    

int main(){
    
    printf("%lf", getDistance(createpoint(2.0, -3.0)), createpoint(-4.0, 5.0));

    return 0;
}
Posted
Updated 22-Nov-20 7:53am
v7

Try to replace
C++
printf("%lf", getDistance(createpoint(2.0, -3.0)), createpoint(-4.0, 5.0));

with
C++
printf("%lf", getDistance(createpoint(2.0, -3.0), createpoint(-4.0, 5.0)));


Advice: use professional text editor.
Professional programmer's editors have features likes indentation, parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[^]
 
Share this answer
 
printf(
 "%lf", 
  getDistance(
   createpoint(2.0, -3.0)) 
   , 
   createpoint(-4.0, 5.0)
)


I broke down the statement you used to call the function.

Note the extra ")" - it closes the getDistance() before the second value is create.


 
Share this answer
 
Quote:
I tried debugging and I just cant figure out what is missing there.

No, you didn't.
Debugging comes once your program has compiled cleanly - until that happens no executable file is produced, and so you can't debug anything!

What you have there is a syntax error, which is the compiler telling you you got it wrong and exactly where. So look at the line the error is reported on - the compiler error will tell you the file name and line number - and compare that with yoru function definition:
C++
printf("%lf", getDistance(createpoint(2.0, -3.0)), createpoint(-4.0, 5.0));
C++
double getDistance(Point a, Point b){

getDistance requires two parameters, and you have teh close bracket in teh wrong place, so you are calling it with one. Try this:
C++
printf("%lf", getDistance(createpoint(2.0, -3.0), createpoint(-4.0, 5.0)));
And your error will go away.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900