Thread: please tell me how to rectify my code

  1. #31
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Glue all four %lf together, just in case...

    Edit: No, i don't think that will do anything different.

    EditMore: Doesn't hurt to try, though.
    Last edited by GReaper; 12-20-2010 at 09:25 AM.
    Devoted my life to programming...

  2. #32
    Registered User
    Join Date
    Dec 2010
    Posts
    29

    Thumbs up

    Code:
    #include <stdio.h>
    #include <math.h>
    
    struct position
    {
        double latitude;
        double longitude;
    };
    
    double computeDistance(const struct position *p1, const struct position *p2)
    {
        const double latitude_dist = p1->latitude - p2->latitude;
        const double longitude_dist = p1->longitude - p2->longitude;
        return sqrt(latitude_dist * latitude_dist + longitude_dist * longitude_dist);
    }
    
    int main(void)
    {
        struct position p1, p2;
        if (scanf("%lf %lf %lf %lf",
            &p1.latitude, &p1.longitude, &p2.latitude, &p2.longitude) == 4)
        {
            printf("Distance = %f\n", computeDistance(&p1, &p2));
        }
        else
        {
            puts("Input error");
        }
        return 0;
    }
    works thanks a lot. i don't know what i did different.
    i built, rebuilt, and debugged every time. this code works.

    input : 1 2 3 4
    output : 2.828427
    Last edited by ilikeapplepie; 12-20-2010 at 09:30 AM. Reason: displaying input and output

  3. #33
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Seems like VS08 finally decided to obey your command an compile the new code instead of the old one!!!
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread