By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

what's wrong with my code!!!?

momotaro
100+
P: 357
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
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
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.