Please help with my code.

This is a discussion on Please help with my code. within the C Programming forums, part of the General Programming Boards category; Ok, I have to write a function called distance that will calculate the distance between 2 points in an x-y ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Please help with my code.

    Ok, I have to write a function called distance that will calculate the distance between 2 points in an x-y coordinate system. Each point will be specified by 2 double values. Also, this function will not contain any input/output code (i.e. no printf or scanf function calls).

    Write a complete program that will test your function.

    How am I supposed to test my results, if I can't have no input/output code? Please help me.


    This is my code, but I haven't finished it yet, because I don't know what to do after that. Please help.

    Code:
    #include <stdio.h>
    #include <math.h>
     
    using namespace std;
     
    double distance(double xOne, double yOne, double xTwo, double yTwo)
                {
                      double xS, yS, result;
                      xS= xTwo - xOne;
                      xS= xS*xS;  // value of x squared under radical
                      yS = yTwo - yOne;
                      yS = yS*yS;  //value of y squared under radical
     
                      result = sqrt(xS + yS);
                      return result;
                }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    It says the FUNCTION cannot contain any input/output. I'm sure you can use it outside the function.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    using namespace std;
    This isn't C
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 03: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, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21