Hello. I am new to c++ and i wonder why this doesn t work. All i want is to calculate the distance beetween 2 points on a plane. However, calculating the distance doesn t work. Please tell me why. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int x1;
printf("Coordinate x of point 1 is: ");
scanf("%d", &x1);
int y1;
printf("Coordinate y of point 1 is: ");
scanf("%d", &y1);
printf("point 1 = A(%d, %d) ", x1, y1);
int x2;
printf("coordinate x of point 2 is: ");
scanf("%d", &x2);
int y2;
printf("coordinate y of point 2 is: ");
scanf("%d", &y2);
printf("point 2 = B(%d, %d) ", x2, y2);
I just took a quick look on my way out. In order to calculate distance you need to use the distance formula and plug in the variables you used for your 2 points.
The distance formula is d=sqrt((x2-x1)^2-(y2-y1)^2)
You will need to include this formula into the code in order to calculate the distance. Hope this helps!
Ah. You're passing the address of the double instead of the double. This is why printf() is dangerous. So the correct line is: printf("Distance beetween two points is:%g\n", razdalja);