469,902 Members | 1,976 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,902 developers. It's quick & easy.

what's wrong with my code!!!?

momotaro
357 100+
am unsing a fuction called distance to compute the distance between two points
but my program seems to not take my inputs because it returs always 0 whatever are the values that i put...plz help!
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. double d;
  4. double distance (double x_1, double x_2, double y_1, double y_2); 
  5. main()
  6. {
  7.     double x_1, x_2, y_1, y_2;
  8.     printf("Enter the coordination of your first point:");
  9.     scanf("%lf %lf", &x_1, &y_1);
  10.     printf("Enter the coordination of your second point:");
  11.     scanf("%lf %lf", &x_2, &y_2);
  12.     printf("The distance is: %f", d);
  13.     scanf("%f", &d);
  14. }
  15. // The definition of the function distance.
  16. double distance (double x_1, double x_2, double y_1, double y_2)
  17. {
  18.         d=sqrt(pow(x_2-x_1, 2)+pow(y_2-y_1, 2));
  19.         return (d);
  20. }
Nov 6 '06 #1
1 1186
horace1
1,510 Expert 1GB
you forgot to call the distance() function, code should be
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. double d;
  4. double distance (double x_1, double x_2, double y_1, double y_2); 
  5. main()
  6. {
  7.     double x_1, x_2, y_1, y_2;
  8.     printf("Enter the coordination of your first point:");
  9.     scanf("%lf %lf", &x_1, &y_1);
  10.     printf("Enter the coordination of your second point:");
  11.     scanf("%lf %lf", &x_2, &y_2);
  12.     d=distance(x_1, x_2, y_1, y_2);               // ** missing
  13.     printf("The distance is: %f", d);
  14.     scanf("%f", &d);
  15. }
  16. // The definition of the function distance.
  17. double distance (double x_1, double x_2, double y_1, double y_2)
  18. {
  19.         d=sqrt(pow(x_2-x_1, 2)+pow(y_2-y_1, 2));
  20.         return (d);
  21. }
  22.  
  23.  
Nov 6 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Chris Geerdink | last post: by
4 posts views Thread by asdf | last post: by
5 posts views Thread by Alexandre Martins | last post: by
1 post views Thread by aa | last post: by
3 posts views Thread by mahsa | last post: by
4 posts views Thread by blah | last post: by
5 posts views Thread by islayer | last post: by
5 posts views Thread by hiqu | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.