Function program! Please help!!

Does anyone know what are my mistakes made?
I am writing this program to calculate the total distance travelled from home to office, office to NTUC and NTUC back to home by asking users to input the x and y coordinate.

However my compiler shows the following errors- error C3861: 'totaldistancetravelled': identifier not found
error C2064: term does not evaluate to a function taking 1 arguments
error C3861: 'sqrt': identifier not found



#include<stdio.h>
double distancefromhometooffice (double hx, double hy, double ox, double oy);
double distancefromofficetoNTUC (double ox, double oy, double nx, double ny);
double distancefromNTUCtohome (double hx, double hy, double nx, double ny);


int main()
{
double hx, hy, ox, oy, nx, ny;
printf("Please enter the coordinates for home", hx, hy);
scanf("%lf %lf", &hx, &hy);
printf("Please enter the coordinate for office", ox, oy);
scanf("%lf %lf", &ox, &oy);
printf("Please enter the coordinate for NTUC", nx, ny);
scanf("%lf %lf", &nx, &ny);

double Distance1= distancefromhometooffice(hx, hy, ox, oy);
printf("%lf", Distance1);

double Distance2= distancefromofficetoNTUC(ox, oy, nx, ny);
printf("%lf", Distance2);

double Distance3= distancefromNTUCtohome(hx, hy, nx, ny);
printf("%lf", Distance3);

double totalDistance= totaldistancetravelled(Distance1, Distance2, Distance3);
printf("%lf", totalDistance);


return 0;

}

double distancefromhometooffice (double hx, double hy, double ox, double oy)
{
double Distance1;
Distance1= sqrt( (hx-ox)*(hx-ox) + (hy-oy)(hy-oy) );
return Distance1;
}

double distancefromofficetoNTUC (double ox, double oy, double nx, double ny)
{
double Distance2;
Distance2= sqrt( (nx-ox)*(nx-ox) + (ny-oy)(ny-oy) );
return Distance2;
}

double distancefromNTUCtohome (double hx, double hy, double nx, double ny)
{
double Distance3;
Distance3= sqrt( (nx-hx)*(nx-hx) + (ny-hy)(ny-hy) );
return Distance3;
}

double totaldistancetravelled (double Distance1, double Distance2, double Distance3)
{
double totalDistance;
totalDistance= Distance1 + Distance2 + Distance3;
return totalDistance;
}
this is easier to read. wrap you code next time with[code][/code]

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
#include<stdio.h>
double distancefromhometooffice (double hx, double hy, double ox, double oy);
double distancefromofficetoNTUC (double ox, double oy, double nx, double ny);
double distancefromNTUCtohome (double hx, double hy, double nx, double ny);


int main()
{
double hx, hy, ox, oy, nx, ny;
printf("Please enter the coordinates for home", hx, hy);
scanf("%lf %lf", &hx, &hy);
printf("Please enter the coordinate for office", ox, oy);
scanf("%lf %lf", &ox, &oy);
printf("Please enter the coordinate for NTUC", nx, ny);
scanf("%lf %lf", &nx, &ny);

double Distance1= distancefromhometooffice(hx, hy, ox, oy);
printf("%lf", Distance1);

double Distance2= distancefromofficetoNTUC(ox, oy, nx, ny);
printf("%lf", Distance2);

double Distance3= distancefromNTUCtohome(hx, hy, nx, ny);
printf("%lf", Distance3);

double totalDistance= totaldistancetravelled(Distance1, Distance2, Distance3);
printf("%lf", totalDistance);


return 0;

}

double distancefromhometooffice (double hx, double hy, double ox, double oy)
{
double Distance1;
Distance1= sqrt( (hx-ox)*(hx-ox) + (hy-oy)(hy-oy) );
return Distance1;
}

double distancefromofficetoNTUC (double ox, double oy, double nx, double ny)
{
double Distance2;
Distance2= sqrt( (nx-ox)*(nx-ox) + (ny-oy)(ny-oy) );
return Distance2;
}

double distancefromNTUCtohome (double hx, double hy, double nx, double ny)
{
double Distance3;
Distance3= sqrt( (nx-hx)*(nx-hx) + (ny-hy)(ny-hy) );
return Distance3;
}

double totaldistancetravelled (double Distance1, double Distance2, double Distance3)
{
double totalDistance;
totalDistance= Distance1 + Distance2 + Distance3;
return totalDistance;
} 



Missed a few things.

your prototype for totaldistancetravelled

#include <cmath>
Last edited on
try including math.h at the start of your code

#include <math.h>
Thanks! I included #include<math.h> and the prototype for totaldistancetravelled.
However, there is still this error- C2064: term does not evaluate to a function taking 1 arguments.
What does it mean? :s
Line Number?
found it.

line 51, 44, 37.

you need a * between those parenthesis. you can just have something like (x * y)(Y * X).

C++ doesn't work that way.
Thanks a lot!
However, there are still errors :
warning C4700: uninitialized local variable 'hy' used
warning C4700: uninitialized local variable 'hx' used
warning C4700: uninitialized local variable 'oy' used
warning C4700: uninitialized local variable 'ox' used
warning C4700: uninitialized local variable 'ny' used
warning C4700: uninitialized local variable 'nx' used
May i know why is that so when i have already initialized my variables?

(though i still can get the output by clicking the [ignore] button)
I believe this will fix it.

You have:

1
2
3
4
5
6
printf("Please enter the coordinates for home", hx, hy);
scanf("%lf %lf", &hx, &hy);
printf("Please enter the coordinate for office", ox, oy);
scanf("%lf %lf", &ox, &oy);
printf("Please enter the coordinate for NTUC", nx, ny);
scanf("%lf %lf", &nx, &ny);


Should be:

1
2
3
4
5
6
printf("Please enter the coordinates for home");
scanf("%lf %lf", &hx, &hy);
printf("Please enter the coordinate for office");
scanf("%lf %lf", &ox, &oy);
printf("Please enter the coordinate for NTUC");
scanf("%lf %lf", &nx, &ny);
YES! It works perfectly now!
THANK YOU SO MUCH!! :)
No Problem. Glad to help.
Topic archived. No new replies allowed.