Thread: Can you check if my code and descriptions are correct?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    Can you check if my code and descriptions are correct?

    Can you all please check if this goes according to the problem stated below, I'm new at this stuff and a friend of mine helped me, but whenever i put values to A1, A2,......I click enter and the screen closes and doesn't give me an answer.
    Also can you check if /*descriptions*/ i put are where they should.
    -----------------------------------------------------------------------------------------------------------------
    Suppose two men (say, A and B) walk away from the same location as follows.
    Man A walks
    A1 miles to east, then
    A2 miles to north-east, then
    A3 miles to east again and stops.
    Man B walks
    B1 miles south, then
    B2 miles west, then
    B3 miles south-west, and stops
    We want to know the straight line distance between the two points where these men stopped. Solve the problem in terms of A1, A2, A3, B1, B2, B3 (user will enter values for these variables) and then write a program to compute the straight line distance between Man A and Man B.






    Code:
    #include <stdio.h>
    #include <math.h>
    
    #define MAX_STR_LEN 1024
    
    
    int main (int argc, char *argvp[]) {
        char line[MAX_STR_LEN];
        /*Declaration of values Entered*/
        int A1, A2, A3, B1, B2, B3; 
        double A2X, B3X, X, Y, ans;
    
        do {
            printf("\nEnter Distance for: A1,A2,A3,B1,B2,B3 : "); /*request information from user*/
            fgets(line,MAX_STR_LEN,stdin);                      /*read input from user*/   
        } while (sscanf(line, "%d ,%d ,%d ,%d ,%d ,%d",         
                        &A1,&A2,&A3,&B1,&B2,&B3) != 6);
         /*Perform Calculation*/               
        A2X = sqrt(pow((double)A2,2)/2);
        B3X = sqrt(pow((double)B3,2)/2);
        X = A1 + A3 + B2 + A2X + B3X;
        Y = A2X + B3X;
        X = pow(X, 2);
        Y = pow(Y, 2);
        ans = sqrt(X + Y);
        printf("\nThe Distance is: %g\n", ans);
        
    
        /*Exit Program*/ 
        return 0;    
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Looks alright with the exception that you forgot to add B1 to the Y component.
    Code:
    Y = A2X + B3X + B1;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. reply to crack code
    By quack in forum C++ Programming
    Replies: 10
    Last Post: 11-04-2003, 10:25 PM
  5. search array program
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 11-15-2002, 07:33 AM