Hey, so I have been programming for a glorious total of three days, and I'm trying to code my first program that uses functions & calls functions. This is literally the 4th thing I have written in code, ever. I'm having issues with my program--I'm doing this in Xcode--it says I have an implicit declaration & conflicting types for the CalculateDistance function, but I really have no idea what that means. This is for a class assignment (
link) which I need to get in asap. I'm working on the Euclidean distance problem. The assignment says that 1) This function should just calculate. It should not do any reading or printing. and 2) main() should call the function and print both the data and the answers. Can anyone help?
this is what I have:
CODE
[code] /*
* distance.h
* distance.c
*
* Created by Nandita Seshadri on 10/2/08.
* This function calculates the Euclidean distance
* between two points.
*
*/
#include<stdio.h>
#include<math.h>
//Function Declarations
int main ()
{
/* Function Call */
double distance1 = CalculateDistance( 0.0, 0.0, 5.0, 5.0);
double distance2 = CalculateDistance (0.0, 0.0, 5.0, 0.0);
double distance3 = CalculateDistance (0.0, 0.0, 0.0, 5.0);
printf(" Point1 Point 2 Distance\n");
printf("(%4.1f, %4.1f)", 0.0, 0.0);
printf("(%4.1f, %4.1f)", 5.0, 5.0);
printf("%4.1f\n", distance1);
printf("(%4.1f, %4.1f)", 0.0, 0.0);
printf("(%4.1f, %4.1f)", 5.0, 0.0);
printf("%4.1f\n", distance2);
printf("(%4.1f, %4.1f)", 0.0, 0.0);
printf("(%4.1f, %4.1f)", 0.0, 5.0);
printf("%4.1f\n", distance3);
return 0;
}
//Distance Function
double CalculateDistance(double x1, double y1, double x2, double y2)
{
double diffx = x1 - x2;
double diffy = y1 - y2;
double diffx_sqr = square (diffx);
double diffy_sqr = square (diffy);
double distance = sqrt (diffx_sqr + diffy_sqr);
return distance;
}